@property UIView* tagsView
从他们的布局来看,标签图形和包含标签的设置按钮被放置在一个 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)
}
定位标签本身只是基于您认为可接受的视图中标签布局的数学。