iOS8:当键盘出现并按下“后退”按钮时,此时下一个视图显示得很慢



我有带有UITextView的ViewController(v2)。我从viewController(V1)推送了那个视图。在V2上当我点击文本视图,键盘出现在点击后退按钮之后,然后在V1上移动。我重复这个过程15到20次,注意到我的应用程序的性能变得非常慢。

问题是当我点击后退按钮时,键盘需要很长时间才能消失:

我正在使用以下代码行:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willShowKeyboard:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
}
- (IBAction)back:(id)sender
{
    [self.navigationController popViewControllerAnimated:NO];
}
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [noteView becomeFirstResponder];
}
- (void)viewWillDisappear:(BOOL)animated {
    [noteView resignFirstResponder];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidHideNotification object:nil];
    [super viewWillDisappear:animated];
 }
- (void)willShowKeyboard:(NSNotification *)notification
{
    [UIView setAnimationsEnabled:NO];
}
- (void)keyboardWillHide:(NSNotification *)notification
{
    [UIView setAnimationsEnabled:NO];
}
- (void)keyboardDidHide:(NSNotification *)notification
{
    [UIView setAnimationsEnabled:NO];
}

当用户按下按钮时,关闭键盘是一个简单的单行代码

- (IBAction)back:(id)sender
{
    [self.view endEditing:YES];
    [self.navigationController popViewControllerAnimated:NO];
}

相关内容

  • 没有找到相关文章

最新更新