美文网首页
iOS 键盘出现通知

iOS 键盘出现通知

作者: cb6a1e2768d1 | 来源:发表于2016-10-29 12:58 被阅读57次
    - (void)viewDidLoad {
       [super viewDidLoad];
       
       [[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 keyboardHeight = keyboardRect.size.height;
        
        
    }
    
    - (void) keyboardWillHide:(NSNotification *)notification{
        
        
    }
    
    - (void)viewDidDisappear:(BOOL)animated {
        [super viewDidDisappear:animated];
        [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
        [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
    
    }
    

    相关文章

      网友评论

          本文标题:iOS 键盘出现通知

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