3

我正在尝试制作一个 UITextView 来检测链接并且当点击没有落在链接上时变得可编辑。

原生 iphone 笔记应用程序展示了这种行为,simplenote 也是如此。

此处概述了我找到的最接近的解决方案:http: //blog.stevex.net/2012/05/editable-uitextview-with-links/ 使用此代码:

// Add the tap gesture recogniser to the view.
- (void)configureTextView {
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self    action:@selector(textViewTapped:)];
textView.editable = NO;
textView.dataDetectorTypes = UIDataDetectorTypeLink;
[textView addGestureRecognizer:recognizer];
}

// Notification from the recogniser that the UITextView was tapped
- (void)textViewTapped:(UIGestureRecognizer *)recognizer {
UITextView *textView = (UITextView *)recognizer.view;
textView.editable = YES;
[textView becomeFirstResponder];
}

// UITextViewDelegate method
- (void)textViewDidEndEditing:(UITextView *)textView {
textView.editable = NO;
}

这个解决方案的问题是它需要长按才能点击链接。

4

0 回答 0