iOS 获取软键盘高度

- (void)viewDidLoad{

       [[NSNotificationCenterdefaultCenteraddObserver:self selector:@selector(keyboardDidShow:)

               name:UIKeyboardDidShowNotification object:nil];  

       [[NSNotificationCenterdefaultCenter] addObserver:self selector:@selector(keyboardDidHide:)

               name:UIKeyboardDidHideNotification   object:nil];

}


- (void)keyboardDidShow:(NSNotification *)nsNotification {

         NSDictionary *userInfo = [nsNotificationuserInfo]; 

         _keyboardSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

        [selfupdateTextViewSize];

}


- (void)keyboardDidHide:(NSNotification *)nsNotification {

          _keyboardSize =CGSizeMake(0.0,0.0);

         [selfupdateTextViewSize];

}


- (void)updateTextViewSize {

         UIInterfaceOrientation orientation =

         [UIApplication sharedApplication].statusBarOrientation;

         CGFloat keyboardHeight =  UIInterfaceOrientationIsLandscape(orientation) ?  _keyboardSize.width          

                                                               :_keyboardSize.height;

          _textView.frame =CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - keyboardHeight);

}




iOS 获取软键盘高度,,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。