防止“选择”和“全选”在 UITextView 中?
我在其他地方发现以下代码阻止在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有几种方法可以解决这个问题。
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.