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 获取软键盘高度,布布扣,bubuko.com

iOS 获取软键盘高度

上一篇:Android的一些疑问


下一篇:android调用.net的webservice的例子获取手机的归属地