我意识到这与大多数帖子相反,但我希望键盘能够保持,即使按下键盘向下按钮。
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; }即使用户按下 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.
更多推荐
有没有办法阻止键盘解雇?
发布评论