无法调整与键盘成比例的uiView高度

时间:2016-12-30 07:07:43

标签: ios objective-c uiview

当我点击文本字段时,执行此方法keyboardDidShow,当我开始输入时,视图将会关闭。这是什么原因?这是我的代码,

else if (textField.tag==2) {

    [self.viewUi setFrame:CGRectMake(0,-110,320,460)];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
}
return YES;

}

- (void)keyboardDidShow:(NSNotification *)notification
{
    // Assign new frame to your view
    [self.viewUi setFrame:CGRectMake(0,-110,320,460)];
}

2 个答案:

答案 0 :(得分:0)

Alwin,这篇特别的帖子可能会帮助你完成这项工作

How to make a UITextField move up when keyboard is present?

或者在NSNotification加载View Controller时尝试添加viewDidLoad观察者。

答案 1 :(得分:0)

 - (void)keyboardDidShow:(NSNotification *)notification
    {
        // Assign new frame to your view
        [self.viewUi setFrame:CGRectMake(0,-110,320,460)];
    }