美文网首页
键盘通知

键盘通知

作者: 竹子4117 | 来源:发表于2018-04-28 09:32 被阅读0次

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

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

    - (void)keyboardWillShow:(NSNotification *)notification
    {
        NSDictionary *userInfo = [notification userInfo];
        NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
        CGRect keyboardRect = [aValue CGRectValue];
        keyboardRect = [self.view convertRect:keyboardRect fromView:nil];
       
        CGFloat keyboardTop = keyboardRect.origin.y;
        CGRect newTextViewFrame = self.view.bounds;
        newTextViewFrame.size.height = keyboardTop - self.view.bounds.origin.y;
       
        NSNumber *animationDuration = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
        NSTimeInterval duration = [animationDuration doubleValue];
       
        [UIView animateWithDuration:duration animations:^{
           
        }];
    }

    - (void)keyboardWillHide:(NSNotification *)notification
    {
        NSDictionary* userInfo = [notification userInfo];
        NSNumber *animationDuration = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
        NSTimeInterval duration = [animationDuration doubleValue];
       
        [UIView animateWithDuration:duration animations:^{
           
        }];
    }

    相关文章

      网友评论

          本文标题:键盘通知

          本文链接:https://www.haomeiwen.com/subject/fdhilftx.html