有没有办法阻止键盘解雇? [英] Is there a way to prevent the keyboard from dismissing?

查看:122
本文介绍了有没有办法阻止键盘解雇?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到这与大多数帖子相反,但我希望键盘能够保持,即使按下键盘向下按钮

I realize that this is the inverse of most posts, but I would like for the keyboard to remain up even if the 'keyboard down' button is pressed.

具体来说,我有两个 UITextField 的视图。使用以下委托方法

Specifically, I have a view with two UITextFields. With the following delegate method

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    return NO;
}

即使用户按下<$,我也能保持键盘保持不变键盘上的c $ c> Done 按钮或点击屏幕上任何其他位置的按钮除了键盘右下方那个讨厌的键盘向下按钮外。

I am able to keep the keyboard up even if the user presses the Done button on the keyboard or taps anywhere else on the screen EXCEPT for that pesky keyboard down button on the bottom right of the keyboard.

我使用这个视图就像一个模态视图(尽管视图与一个在UINavigationController中被推送的ViewController相关联),所以从用户的角度来看它确实最好用一直保持键盘。如果有人知道如何实现这一目标,请告诉我!谢谢!

I am using this view like a modal view (though the view is associated with a ViewController that gets pushed in a UINavigationController), so it really works best from a user perspective to keep the keyboard up all of the time. If anyone knows how to achieve this, please let me know! Thanks!

更新仍然没有解决方案!当按下完成时,它会触发 textFieldShouldReturn ,但是当解除按钮,它会触发 textFieldDidEndEditing 。我无法阻止 textField 结束编辑,或从不消失。不知何故,我真的想要一个方法来检测 Dismiss 按钮并忽略它。如果你知道一种方法,请赐教!

UPDATE Still no solution! When Done is pressed, it triggers textFieldShouldReturn, but when the Dismiss button is pressed, it triggers textFieldDidEndEditing. I cannot block the textField from ending editing or it never goes away. Somehow, I really want to have a method that detects the Dismiss button and ignores it. If you know a way, please enlighten me!

推荐答案

有办法做到这一点。 因为 UIKeyboard 子类 UIWindow ,唯一可以进入 UIKeyboard 的方式是另一个 UIWindow

There IS a way to do this. Because UIKeyboard subclasses UIWindow, the only thing big enough to get in UIKeyboard's way is another UIWindow.

- (void)viewDidLoad {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(coverKey) name:UIKeyboardDidShowNotification object:nil];
    [super viewDidLoad];
}

- (void)coverKey {
    CGRect r = [[UIScreen mainScreen] bounds];
    UIWindow *myWindow = [[UIWindow alloc] initWithFrame:CGRectMake(r.size.width - 50 , r.size.height - 50, 50, 50)];
    [myWindow setBackgroundColor:[UIColor clearColor]];
    [super.view addSubview:myWindow];
    [myWindow makeKeyAndVisible];
}

这适用于iPhone应用程序。没试过用iPad。您可能需要调整 myWindow 的大小。另外,我没有在 myWindow 上进行任何内存管理。所以,也要考虑这样做。

This works on iPhone apps. Haven't tried it with iPad. You may need to adjust the size of myWindow. Also, I didn't do any mem management on myWindow. So, consider doing that, too.

这篇关于有没有办法阻止键盘解雇?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆