3

如何为 UITextView 启用滑动手势识别?

这是我的代码,附加到它的事件没有触发。它适用于水龙头,但不适用于滑动。

// Add swipe support for easy textview content clean up
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(eraseTextWithSwipe:)];
[targetContent addGestureRecognizer:swipe];
[swipe release];

我怎么做?

4

2 回答 2

2

我找到了一个适合我的解决方案。

你需要设置委托(参考上面的代码)

swipe.delegate = self;

那么你需要添加一个委托来跟踪多个手势,这将能够跟踪滑动和滚动

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGesture
{
    yourTextbox.scrollEnabled = NO;
    return YES;
}

在回调函数中重新启用滚动(在上面的示例中是 eraseTextWithSwipe)

于 2010-09-14T15:21:51.807 回答
2

谢谢你。您的解决方案有效。我只需要设置委托并在提到的委托方法中返回 YES。如果不是出于可用性原因,您不必禁用 UITextView 上的滚动。

于 2010-10-03T13:52:18.447 回答