您的位置:首页 > 产品设计 > UI/UE

iOS 键盘弹出遮挡UITextField解决方法

2017-04-05 11:30 316 查看
 //增加监听,当键退出时收出消息

    [[NSNotificationCenter
defaultCenter] addObserver:self

                                             selector:@selector(keyboardWillHide:)

                                                 name:UIKeyboardWillHideNotification

                                               object:nil];

//开始编辑时
视图上移
如果输入框不被键盘遮挡则不上移。

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{

    

    CGFloat rects;

    if(
1==textField.tag ||2==textField.tag
||3==textField.tag||4==textField.tag)

    {

        rects = self.view.frame.size.height
- (_topview.frame.origin.y +
40*textField.tag +
216 +50);

    }

    else

    {

        rects = self.view.frame.size.height
- (_centerView.frame.origin.y
+ 40*(textField.tag-4)  +
216 +50);

    }

    

    if (rects <=
0) {

        

        [UIView
animateWithDuration:0.3
animations:^{

            

            CGRect frame =
self.view.frame;

            

            frame.origin.y = rects;

            

            self.view.frame = frame;

            

        }];

        

    }

    return
YES;

    

}

//当键退出时调用

- (void)keyboardWillHide:(NSNotification *)aNotification

{

    [UIView
animateWithDuration:0.3
animations:^{

        

        CGRect frame =
self.view.frame;

        

        frame.origin.y =
64.0;

        

        self.view.frame = frame;

        

    }];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐