首页 > 移动平台 > 详细

iOS 获取软键盘高度

时间:2014-04-04 02:48:12      阅读:508      评论:0      收藏:0      [点我收藏+]

- (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 获取软键盘高度

原文:http://blog.csdn.net/leochang130731/article/details/22874263

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!