我想我在 iOS 7 中的 UITextView 中遇到了一个错误,但我找不到任何对它的引用或讨论,所以在这里尝试确认我没有遗漏任何东西:
错误
我有一个 UITextView 设置如下:
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(20, 100, 280, 140)];
textView.editable = NO;
textView.dataDetectorTypes = UIDataDetectorTypeLink;
textView.backgroundColor = [UIColor lightGrayColor];
textView.delegate = self;
textView.text = [NSString stringWithFormat:@"This is a UITextView in a UIViewController. It has editable %d, selectable %d, dataDectorTypes %d (UIDataDetectorTypeLink), and a link! http://www.google.com.\n\nIf you click the link, it works normally. If you press, then drag your finger away to cancel the touch, the highlight goes away but the action still fires. Shouldn't the action not fire?", textView.editable, textView.selectable, textView.dataDetectorTypes];
[self.view addSubview:textView];
textview 文本包含一个链接,如果您单击该链接,它将按预期工作:它会回调委托,它只会弹出一个警报:
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"You clicked the link!" message:@"You clicked the link. Maybe you tried to move away to cancel the touch, but you clicked it anyway." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
return NO;
}
问题是,如果您按下链接,然后尝试拖动以取消触摸:链接的高亮状态消失,但一旦您的手指离开屏幕,代理就会触发。
我无法找到一种方法来告诉 textview 在它应该取消时不要触发,或者检测它应该已经取消。
我确信这是一个错误,因为视觉按下/取消状态和动作触发不匹配。