![](/img/trans.png)
[英]Issue with horizontal scrollview inside a vertical scrollview in ios swift
[英]Horizontal Pan Inside Vertical Scrollview
我的滾動視圖僅限於垂直滾動。 在其中,我想使用UIPanGestureRecognizer來僅識別水平平移的視圖。
同樣,水平識別器也會獲勝並完全阻止滾動視圖滾動。
我希望水平平移在檢測到大部分為水平手勢時獲勝,否則垂直滾動應會獲勝。 與郵箱的工作方式非常相似,或在iOS8 Mail.app中滑動
您可以使用UIGestureRecognizerDelegate
方法之一(例如gestureRecognizerShouldBegin:
來指定在哪種情況下觸發哪個平移手勢。
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
// If the gesture is a pan, determine whether it starts out more
// horizontal than vertical than act accordingly
if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
UIPanGestureRecognizer *panGestureRecognizer = (UIPanGestureRecognizer *)gestureRecognizer;
CGPoint velocity = [panGestureRecognizer velocityInView:self.view];
if (gestureRecognizer == self.scrollView.panGestureRecognizer) {
// For the vertical scrollview, if it's more vertical than
// horizontal, return true; else false
return fabs(velocity.y) > fabs(velocity.x);
} else {
// For the horizontal pan view, if it's more horizontal than
// vertical, return true; else false
return fabs(velocity.y) < fabs(velocity.x);
}
}
else
return YES;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.