码迷,mamicode.com
首页 > 移动开发 > 详细

弹出键盘,输入框上移问题 iOS

时间:2017-06-22 13:21:41      阅读:317      评论:0      收藏:0      [点我收藏+]

标签:int   ram   输入框   rds   rem   boa   rect   UI   elf   

 viewDidLoad 中添加监听

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

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

 

实现两个监听方法

- (void)keyboardShow:(NSNotification *)notification{

    if(currentTextField.tag >= 1000){

          CGSize size = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue].size;//键盘大小

        CGFloat keyBoardHeight = size.height+10;//键盘高度,富余10点高度

 

        // screenHeight 手机屏幕总高度, 64是导航栏的高度, currentTextField.bottomY 当前textField的底部位置,

           CGFloat shouldMoveHeight = keyBoardHeight-( screenHeight - 64-currentTextField.bottomY);

        if(shouldMoveHeight > 0){

            _bgScrollView.contentOffset = CGPointMake(0, shouldMoveHeight);

        }

    }

}

- (void)keyboardHidden:(NSNotification *)notification{

    _bgScrollView.contentOffset = CGPointMake(0, 0);

}

 

- (void)dealloc

{

    [[NSNotificationCenter defaultCenter]removeObserver:self];

    

}

 

弹出键盘,输入框上移问题 iOS

标签:int   ram   输入框   rds   rem   boa   rect   UI   elf   

原文地址:http://www.cnblogs.com/ios-wyh/p/7064284.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!