我想在 UITextView 中禁用文本编辑,只有光标应该保留。我已经禁用了键盘、剪切复制粘贴菜单和缩放编辑模式。但是仍然存在一个问题 - 如果我双击 TextView 它会选择整个单词。还有一件事,我怎样才能让光标选择任何地方,而不仅仅是单词的结尾或开头?
我做了截图,这更好地描述了我的问题,但由于声誉而无法发布。所以我希望你能明白我的意思。
UITextView 的子类:
#import "UIUneditableTextView.h"
@implementation UIUneditableTextView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
UIMenuController *menuController = [UIMenuController sharedMenuController];
if (menuController) {
[UIMenuController sharedMenuController].menuVisible = NO;
}
return NO;
}
-(void)addGestureRecognizerForLongPress:(UIGestureRecognizer *)gestureRecognizer
{
if ([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]]){
gestureRecognizer.enabled = NO;
}
[super addGestureRecognizer:gestureRecognizer];
return;
}
@end