2010-09-13 115 views
3

如何啓用UITextView的滑動手勢識別?如何啓用UITextView的滑動手勢

這是我的代碼,附加到它的事件不會觸發。它適用於水龍頭,而不是輕掃。

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

我該怎麼做?

+0

我不確定這個問題中的任何建議是否有幫助;它沒有被接受的答案。 http://stackoverflow.com/questions/2042930/successful-swipe-in​​-uitextview – Greg 2010-09-13 16:36:58

+0

謝謝你的評論,但不適用,我已經看到它。這使用了蘋果在iPhone 4.x中不推薦的技術。 – amok 2010-09-14 14:16:50

回答

2

我發現了一個適合我的解決方案。

您需要設置委託(上面提到的代碼)

swipe.delegate = self; 

,那麼你需要添加一個委託跟蹤多個手勢,這將能夠跟蹤輕掃和滾動

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

重新啓用在回調函數的滾動(在上面eraseTextWithSwipe的例子)

+0

它的工作原理。好的解決方案 – echo 2014-03-02 18:40:48

2

謝謝。你的解決方案有效我只需要在提到的委託方法中設置委託並返回YES。 如果不是出於可用性的原因,您不必禁用UITextView上的滾動。