轮流调用 UIKeyboardWideNotification

Bri*_*tus 5 rotation hide uikeyboard ios resignfirstresponder

我已经实现了这个:

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
Run Code Online (Sandbox Code Playgroud)

因为我有一个滚动条和其他东西。但问题是iPad键盘上有一个隐藏键盘的按钮,但并没有停止编辑(闪烁的行依然存在)

我希望如果他隐藏键盘,文本在键盘动画时间后会自行消失。这很好用。

但是如果我旋转,该方法将被调用并且文本字段将自行退出(甚至被调用一次,而是三次)

UIKeyboardWillHideNotification当 UI 旋转时如何停止触发?

如果不是这样,当点击该按钮时,我如何正确地退出响应者?

这是我的代码:

float keyboardHeightSize;
- (void)keyboardWillShow:(NSNotification*)notification {
    keyboardHeightSize = [[[notification userInfo]objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue].size.height;

    [_scroller setContentSize:CGSizeMake(0, 1954+keyboardHeightSize)];

}

- (void)keyboardWillHide:(NSNotification*)notification {

    [_scroller setContentSize:(CGSizeMake(0, 1954))];

    CGFloat keyboardAnimationDuration = [[[notification userInfo]objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];

    [self performSelector:@selector(resignResponders) withObject:nil afterDelay:keyboardAnimationDuration];

}

-(void)resignResponders {

    for (id textField in self.scroller.subviews)
    {
        if ([textField isKindOfClass:[UITextField class]])
        {
            UITextField *theTextField = textField;
            if ([theTextField isFirstResponder]) {
                [theTextField resignFirstResponder];

            }

        }
    }

}
Run Code Online (Sandbox Code Playgroud)