防止“选择”和“全选”在 UITextView 中?

发布于 2024-12-22 13:51:12 字数 331 浏览 2 评论 0原文

我在其他地方发现以下代码阻止在 UITextView 中复制和粘贴。但我无法在不完全禁用所有 UITextField 的情况下使类似的代码起作用来阻止 UITextView 中的选择和粘贴。

当我在编辑时触摸文本字段时,会显示“选择”和“全选”方法。换句话说,如果我停止输入数字,只需触摸并按住正在编辑的字段,就会弹出“选择”和“全选”方法。我不希望这种事发生。有什么建议吗?

@implementation UITextView (DisableCopyPaste)
- (BOOL)canBecomeFirstResponder
{
    return NO;
}
@end

I've found elsewhere that the following code prevents Copy and Paste in a UITextView. But I can't make analogous code work to prevent Select and Paste in a UITextView without totally disabling all the UITextFields.

The Select and Select All methods show up when I touch in the text field while editing. In other words, if I stop entering numbers and simply touch and hold in the field that is being edited, the Select and Select All methods pop up. I don't want that to happen. Any suggestions?

@implementation UITextView (DisableCopyPaste)
- (BOOL)canBecomeFirstResponder
{
    return NO;
}
@end

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

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

发布评论

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

评论(1

长不大的小祸害 2024-12-29 13:51:12

有几种方法可以解决这个问题。

1)您可以设置 UITextView 的委托。该委托包含一个方法 (- (BOOL)textViewShouldBeginEditing:(UITextView *)textView),您可以实现该方法以避免选择。

2)您还可以将UITextView的属性userInteractionEnabled设置为NO。然后它就不会再滚动了。

There are a couple of ways to solve this problem.

1) You could set the UITextView's delegate. The delegate contains a method (- (BOOL)textViewShouldBeginEditing:(UITextView *)textView) that you could implement to avoid selection.

2) You could also set the UITextView's property userInteractionEnabled to NO. Then it won't scroll anymore though.

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