[英]iOS:I have a requirement with textview become first responder
當[sendTextField becomeFirstResponder]
時, keyboard
會upspring
,並self.view
將upspring了。
我有一個要求,當[sendTextField becomeFirstResponder]
, keyboard
[sendTextField becomeFirstResponder]
,但是self.view不會彈出嗎?
編輯:為使我的問題更清楚,我添加了一張圖片:
我的要求是: tableview
不能彈起,而textview's back
keyboard
彈起是可以彈起的。
編輯:對於Ajay Gabani
的回答,我在我的測試ipnone-5s
使用TPKeyboardAvoiding
的例子,我發現這一點,也的tableView upspring
與keyboard
,畫面將顯示:
來源狀態:
tableview的后代:
抱歉,我無法評論您的問題。
對於您的情況“ [sendTextField成為FirstResponder]時,鍵盤出現問題,但self.view不會出現問題嗎?”
您可以使用鍵盤外觀在滾動視圖或表視圖中管理文本字段。
希望這對您有幫助。
如果您不想使用第三方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.