UIKeyboardWillHideNotification在旋转中调用

时间:2015-01-16 02:38:29

标签: ios rotation hide uikeyboard resignfirstresponder

我已经实现了这个:

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];

因为我有卷轴和其他东西。但问题是iPad在键盘上有一个按钮来隐藏键盘,但它不会停止编辑(闪烁线仍然存在)

我希望如果他隐藏键盘,文本会在键盘动画之后自行重新调整。这很好。

但是如果我旋转,则会调用该方法并且textField会自行调用(甚至不会调用一次,但会调用三次)

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

如果不是这样,那么在点击该按钮时如何正确地重新响应响应者?

这是我的代码:

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];

            }

        }
    }

}

0 个答案:

没有答案