【问题标题】:dyanmically add multiple UITextviews with new UITextView above the old UITextview在旧 UITextview 上方动态添加多个 UITextview 和新 UITextView
【发布时间】:2014-05-07 13:14:10
【问题描述】:

我有一个UITextView 用于在文章中添加 cmets。在这个UITextView 下方是一个名为'添加另一个评论'UIButton。单击此UIButton 时,必须创建另一个UITextView,以便将旧UITextView 推到新@ 下方。我必须能够做多少次我想要的。

编辑:我的问题不是创建UITextView,而是将旧文本视图推到新文本视图下方。应该是这样的:

a) 在打开 cmets 部分之前

b) 打开 cmets 部分后

【问题讨论】:

  • 当您说旧的“低于”新的时,旧的是否也低于按钮?就像所有旧的 cmets 都被推到按钮下方,而新评论的 textview 总是在按钮上方?

标签: ios iphone uitextview autolayout


【解决方案1】:

嗨,约翰,是的,您可以在单击按钮后创建 uitextfield,您必须编写如下代码

- (IBAction)addText:(id)sender
{
CGRect textfieldFrame = CGRectMake(0.0, 0.0, 100.0, 30.0);
UITextField *textField = [[UITextField alloc] initWithFrame:textfieldFrame];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.font = [UIFont systemFontOfSize:15];
textField.placeholder = @"enter text";
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.keyboardType = UIKeyboardTypeDefault;
textField.returnKeyType = UIReturnKeyDone;
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;    
textField.delegate = self;
[self.view addSubview:textField];



}

this link also use full for the reference

【讨论】:

    【解决方案2】:

    只需更改动画块中旧文本视图的 y 位置

    [UIView animateWithDuration:1.0 动画:^{

    // 设置中心 = btn.y+btn 高度+0.5*tetview 高度 + 按钮下方的任何空间(如果需要)

    }];

    我几乎没有疑问 正在使用滚动视图?用户将如何查看以前的 cmets ?如果文本高度大于 textview 的高度怎么办?

    【讨论】:

    • 是的,我正在使用作为子视图添加到 UIScrollView 的 UIView。检查了它。在第一张图片中,您可以看到一个 'Notes & cmets' 按钮。单击时,它会打开已保存的评论框(UITextViews)列表。这在第二张图片中进行了说明,其中可以看到两个评论框(当然可以有很多!)。我现在不关心文字高度。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多