如何阻止 UITextField 响应摇动手势?

发布于 2024-09-18 07:46:28 字数 937 浏览 1 评论 0原文

默认情况下,如果您在 UITextField 中输入文本时摇动 iPhone,则会出现一个小框,询问您是否要撤消输入。我怎样才能防止这种情况发生?我浏览了 UITextFieldUITextFieldDelegateUITextInputTraits 文档,没有发现任何与抖动相关的内容。

想必我可以继承 UITextField 来忽略摇动事件,但我对自己不搞砸其他事情的能力并不完全有信心。我喜欢这样的东西:

textField.respondsToShake = FALSE;

最好的方法是什么?

By default, if you shake the iPhone while entering text in a UITextField, a little box will appear asking if you want to undo typing. How can I prevent this from happening? I looked through the UITextField, UITextFieldDelegate, and UITextInputTraits docs and found nothing relating to shaking.

Presumably I could subclass UITextField to ignore the shake event, but I'm not exactly confident in my ability to not screw other things up. I'd love something like

textField.respondsToShake = FALSE;

What's the best way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暗喜 2024-09-25 07:46:28
[UIApplication sharedApplication].applicationSupportsShakeToEdit = NO;
[UIApplication sharedApplication].applicationSupportsShakeToEdit = NO;
随心而道 2024-09-25 07:46:28

您可以尝试子类化 UITextField 并重写 canPerformAction:withSender:,这样它将禁止 undo: 操作。但随后您将无法通过摇动和上下文菜单进行撤消。

You could try to subclass UITextField and override canPerformAction:withSender: in such a way that it will disallow the undo: action. But then you lose undo both by shaking and through the context menu.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文