ios 当键盘出现遮挡视图 视图上移Bug

来源:互联网 发布:网络女主播豆豆 编辑:程序博客网 时间:2024/06/06 00:12

在做iOS开发时,当键盘出现 遮挡了视图的输入框 按照常理 把视图的y坐标上移 当收键盘时在还原视图的原来位置.

       CGRect textViewFrame = textView.frame;
        int offset = textViewFrame.origin.y-(_backScrollView.frame.size.height-216.0);
        NSTimeInterval animationDuration = 0.30f;
        [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
        [UIView setAnimationDuration:animationDuration];
        if (offset<0) {
            _backScrollView.frame = CGRectMake(0.0f, offset, self.view.frame.size.width, self.view.frame.size.height);
        }

   这是我们在键盘弹出后代理方法里面写的 视图上移


   收键盘时的代码:
   _backScrollView.frame = cgrectmake(0,0.self.view.frame.size.width,self.view.frame.size.height);


   这样写的问题时  键盘第二次弹出时 键盘依然会遮挡视图 因为这时textView.frame 已经不是最初的frame  以及导航的影响

   解决的办法是:

        在最开始的时候定义一个变量_origineFrame记录一下 frame

       然后再收键盘时写这样的代码 就解决了问题

       _backScrollView.frame = _origineFrame;


0 0
原创粉丝点击