【问题标题】:How to enable swipe gesture for a UITextView如何为 UITextView 启用滑动手势
【发布时间】:2010-09-13 15:04:00
【问题描述】:

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

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

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

我该怎么做?

【问题讨论】:

  • 我不确定这个问题中的任何建议是否会有所帮助;其中没有公认的答案。 stackoverflow.com/questions/2042930/…
  • 感谢您的评论,但这并不适用,我已经看到了。这使用了 Apple 在 iPhone 4.x 中不推荐的技术。

标签: iphone ipad gesture-recognition


【解决方案1】:

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

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

swipe.delegate = self;

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

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

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多