簡體   English   中英

iOS:我有一個要求,要求textview成為第一響應者

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

[sendTextField becomeFirstResponder]時, keyboardupspring ,並self.view將upspring了。

我有一個要求,當[sendTextField becomeFirstResponder]keyboard [sendTextField becomeFirstResponder] ,但是self.view不會彈出嗎?

編輯:為使我的問題更清楚,我添加了一張圖片:

tableview不會彈起,而textview的后彈和彈出鍵盤

我的要求是: tableview不能彈起,而textview's back keyboard彈起是可以彈起的。

編輯:對於Ajay Gabani的回答,我在我的測試ipnone-5s使用TPKeyboardAvoiding的例子,我發現這一點,也的tableView upspringkeyboard ,畫面將顯示:

來源狀態:

起源狀態

tableview的后代:

Tableview的后代

抱歉,我無法評論您的問題。

對於您的情況“ [sendTextField成為FirstResponder]時,鍵盤出現問題,但self.view不會出現問題嗎?”

您可以使用鍵盤外觀在滾動視圖或表視圖中管理文本字段。

TPKeyboardAvoiding

希望這對您有幫助。

如果您不想使用第三方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