有没有办法阻止键盘解雇?

编程入门 行业动态 更新时间:2024-10-28 13:26:35
本文介绍了有没有办法阻止键盘解雇?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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.

更多推荐

有没有办法阻止键盘解雇?

本文发布于:2023-10-31 01:24:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1544579.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:没有办法   键盘

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!