【问题标题】:iOS:I have a requirement with textview become first responderiOS:我要求 textview 成为第一响应者
【发布时间】:2016-10-26 20:09:32
【问题描述】:

[sendTextField becomeFirstResponder] 出现时,keyboard 将出现upspringself.view 也会出现。

我有一个要求,当[sendTextField becomeFirstResponder]keyboardupspring,但是self.view不upup?

编辑:为了更清楚我的问题,我添加了一张图片:

我的要求是: tableview 不弹出,textview's back 弹出 keyboard 弹出窗口。

编辑:对于Ajay Gabani 的答案,我在ipnone-5s 中使用TPKeyboardAvoiding 的示例进行了测试,我发现了这个,tableView 也是upspringkeyboard,图片将显示:

原产地状态:

tableview 的兴起:

【问题讨论】:

  • 到目前为止你做了什么??

标签: ios objective-c keyboard uitextview


【解决方案1】:

抱歉,我无法对您的问题发表评论。

对于您的情况“当 [sendTextField becomeFirstResponder] 时,键盘弹出,但 self.view 不弹出?”

您可以使用键盘外观管理滚动视图或表格视图中的文本字段。

TPKeyboardAvoiding

希望这对你有帮助。

【讨论】:

  • 谢谢你回答我的问题,你满足我的要求。顺便问一下,“For your case”当[sendTextField becomeFirstResponder]时,键盘弹出,但self.view不弹出?”是什么意思,我的英文不好,你的表达是什么意思?
  • 不,不是英语,我完全理解您的要求。我只是想澄清您的要求案例,即您希望显示键盘而不会出现任何其他应用程序和 UIView 的不当行为。
  • 很抱歉,在我的项目中测试后,这不适用于我的要求,您的示例我仔细测试并在tableview的底部找到,它也会上串。
  • 它还支持带有滚动视图的tableview和collectionview。如果您想将此案例与表格视图一起使用,请使用 TPKeyboardAvoidingTableView,而对于 collectionview,请使用 TPKeyboardAvoidingCollectionView。请在示例项目库中搜索。
  • 我很抱歉测试TPKeyboardAvoiding,你可以看到我的EDIT有问题,tableView upspring with keyboard,Label 29是tableView的结尾,这个例子是你提供给我的。
【解决方案2】:

如果您不想使用 3rd 方 SDK 您可以像这样以编程方式使用观察者和管理 UIView 框架

- (void)viewDidLoad {

[super viewDidLoad];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardDidShowNotification object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil];
}

- (void)keyboardWillShow:(NSNotification*)aNotification {
[UIView animateWithDuration:0.25 animations:^
 {
     CGRect newFrame = [customView frame];
     newFrame.origin.y -= [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height; // Adjust your tableview position by taking keyboard height
     [tableView setFrame:newFrame];

 }completion:^(BOOL finished)
 {

 }];
}

- (void)keyboardWillBeHidden:(NSNotification*)aNotification {
[UIView animateWithDuration:0.25 animations:^
 {
     CGRect newFrame = [customView frame];
     newFrame.origin.y += [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height; // // Adjust your tableview position
     [tableView setFrame:newFrame];

 }completion:^(BOOL finished)
 {

 }];

}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self.view endEditing:YES];
}

【讨论】:

    猜你喜欢
    • 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
    相关资源
    最近更新 更多