键盘应始终显示在屏幕上

时间:2015-03-20 12:34:56

标签: iphone keyboard xcode-6.2

仅在点击iPhone应用程序的文本框后才会显示键盘。但是当我的屏幕获得光标/访问时,我需要键盘始终出现在特定的屏幕上。

提前致谢。

1 个答案:

答案 0 :(得分:1)

像这样打开

    -(void)viewWillAppear:(BOOL)animated
    {
        //Add Observer
        [super viewWillAppear:animated];  
        [textField becomeFirstResponder];
    }

And dismiss when your view goes off

-(void)viewWillDisappear:(BOOL)animated
    {
        //Add Observer
        [super viewWillDisappear:animated];  
        [self.view endEditing:YES];
    }

快速使用此方法

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated);
    nametxtreg.becomFirstResponder()
}

override func viewWillDisappear(animated: Bool) {
    super.viewWillDisappear(animated);
    textView.resignFirstResponder()
    self.view.endEditing(true)
}