从布局的外观上来看,包含标签的标签图形和设置按钮被安置在一个UIView的(我们称此为@property UIView* tagsView
),再有就是有一个UITextView,在他们是一个特殊的视图放置具有圆角的特殊UIView对象(可能带有通过Quartz提供的.cornerRadius),其中包含每个可接受标记的文本(让我们称这个容器为@property UIView* tagsEditorView
)。
然后,要回答有关向上移动标签栏和标签字段以添加/编辑标签(或按下完成时向下)的问题,最简单的方法是使用UIView类的动画方法。
CGFlot keyboardTop = y; // calculate keyboard top here.
newTagsFrame = CGFrameMake(0, 0, _tagsView.size.width, _tagsView.size.height);
newTagsEditorFrame = CGFrameMake(0, _tagsView.size.height, _tagsView.size.width, keyboardTop);
[UIView animateWithDuration:0.5 animations:^{
_tagsView.frame = newTagsFrame;
_tagsEditorView.frame = newTagsEditorFrame;
}];
来回答第二个问题,对于形状,如上面提到的,如果你#import <QuartzCore/QuarzCore.h>
,您可以设置cornerRadius和形状的物品,只要你想。对于项目本身,只要能够将它们作为UIButton
对象(或者如果您愿意的话,可以使用UILabel
对象)作为tagsEditorView的子视图添加,按照您认为合适的方式进行定位。
#import <QuartzCore/QuartzCore.h>
// ...
// at the point at which it is determined that a tag is valid, non-duplicated, etc.
UILabel* tagLabel = [[UILabel alloc] init];
// set the label text, background color, text color, borders, frame size, etc
// at the point at which it is determined that a tag is valid, non-duplicated, etc.
tagLabel.layer.cornerRadius = (tagButton.frame.size.height/2);
_tagsArray = [_tagsArray.mutableCopy append:tagLabel];
[_tagsEditorView addSubview:tagLabel];
// ...
// at the point of ultimate display
for (UILabel* tagLabel in _tagsArray)
{
// the following will give an initial rect to work with based on label contents,
// and the font can be changed if desired by changing the minFontSize: argument
CGRect tagLabelRect
= [tagLabel.text sizeWithFont:[myFont fontWithSize:_myFontSize]
minFontSize:_myFontSize
actualFontSize:&actualFontSize
forWidth:_tagsEditorView.frame.size.width
lineBreakMode:NSLineBreakByWordWrapping];
// calculate tagLabel.frame based on individual tag and on preceding
// number of edited tags (filling/wrapping left as an exercise to reader)
}
定位标签本身只是基于您认为您认为可接受的标签布局的数学。
为什么在Mono Touch和Objecive-C上标记你的问题? (因为您试图复制他们的应用程序的一部分而不是用户的API,所以删除了Tumblr标记) – 2013-05-09 21:42:19
因为我对解决方案类型没有偏好。我个人使用Xamarin的工具,但我不介意Obj-C的答案。 – pierceboggan 2013-05-09 22:40:37