我有一個垂直滾動UIScrollView
。我也想處理水平鍋,同時允許默認的垂直滾動行爲。我在滾動視圖上放置了一個透明的UIView
,併爲其添加了一個平移手勢識別器。通過這種方式,我可以很好地使用平底鍋,但滾動視圖不會收到任何手勢。通過UIScrollView截取平移手勢中斷滾動
我已經實現了以下UIPanGestureRecognizerDelegate
方法,希望能夠限制我的手勢識別器只水平平底鍋,但是這並沒有幫助:
- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer
{
// Only accept horizontal pans here.
// Leave the vertical pans for scrolling the content.
CGPoint translation = [gestureRecognizer translationInView:self.view];
BOOL isHorizontalPan = (fabsf(translation.x) > fabsf(translation.y));
return isHorizontalPan;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return (otherGestureRecognizer == _scrollView.panGestureRecognizer);
}
你試過'[panGesture setCancelsTouchesInView:NO];'?在'shouldRecognizeSimultaneouslyWithGestureRecognizer'中簡單地返回YES也許可以幫助你找出問題出在哪裏。 –
剛剛嘗試過,沒有區別。 – Macondo2Seattle