gpt4 book ai didi

ios - 垂直 ScrollView 内的水平平移

转载 作者:行者123 更新时间:2023-11-28 19:54:34 25 4
gpt4 key购买 nike

我有一个仅限于垂直滚动的 ScrollView 。在它里面,我想要有一个 UIPanGestureRecognizer 的 View 只识别水平平移。

与水平识别器一样,它会获胜并阻止 ScrollView 滚动。

如果检测到主要是水平手势,我希望水平平移获胜,否则垂直滚动应该获胜。与 Mailbox 的工作方式非常相似,或者在 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;
}

关于ios - 垂直 ScrollView 内的水平平移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27195236/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com