简体   繁体   English

iOS:我有一个要求,要求textview成为第一响应者

[英]iOS:I have a requirement with textview become first responder

When the [sendTextField becomeFirstResponder] , the keyboard will upspring , and self.view will upspring too. [sendTextField becomeFirstResponder]时, keyboardupspring ,并self.view将upspring了。

I have a requirement , when [sendTextField becomeFirstResponder] , the keyboard upspring, but self.view do not upspring? 我有一个要求,当[sendTextField becomeFirstResponder]keyboard [sendTextField becomeFirstResponder] ,但是self.view不会弹出吗?

EDIT:For more clear for my question, I add a picture: 编辑:为使我的问题更清楚,我添加了一张图片:

tableview不会弹起,而textview的后弹和弹出键盘

My requirement is: The tableview do not upspring and the textview's back upspring with keyboard popup. 我的要求是: tableview不能弹起,而textview's back keyboard弹起是可以弹起的。

EDIT:For Ajay Gabani 's answer, I test in my ipnone-5s using TPKeyboardAvoiding 's example , and I found this, the tableView also upspring with the keyboard , the picture will show: 编辑:对于Ajay Gabani的回答,我在我的测试ipnone-5s使用TPKeyboardAvoiding的例子,我发现这一点,也的tableView upspringkeyboard ,画面将显示:

The origin status: 来源状态:

起源状态

The tableview upspring: tableview的后代:

Tableview的后代

Sorry I am not able to comment on your question. 抱歉,我无法评论您的问题。

For your case "when [sendTextField becomeFirstResponder], the keyboard upspring, but self.view do not upspring?" 对于您的情况“ [sendTextField成为FirstResponder]时,键盘出现问题,但self.view不会出现问题吗?”

You can manage textfield within scrollview or tableview with keyboard appearance. 您可以使用键盘外观在滚动视图或表视图中管理文本字段。

TPKeyboardAvoiding TPKeyboardAvoiding

Hope this might help you. 希望这对您有帮助。

If you don't want to use 3rd party SDK you can use observer and manage UIView frame programatically like this 如果您不想使用第三方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];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM