從佈局的外觀上來看,包含標籤的標籤圖形和設置按鈕被安置在一個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