gpt4 book ai didi

ios - 禁用 UIScrollView 拖动事件到特定方向并将事件发送到 super

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:45:50 27 4
gpt4 key购买 nike

我有 UIView 并附加了一个 UIPanGestureRecognizer。在 UIView 中,我有启用了分页的 UIScrollView,我设置了内容大小,这样 scrollView 就可以 滚动到左边。

问题:

我希望当用户尝试将 scrollView 拖动到右侧时,将事件向上发送到 UIView,以便“UIPanGestureRecognizer”可以处理触摸事件

最佳答案

终于,在 6 小时后我弄明白了我继承了 UIScrollView 并实现了 gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer 委托(delegate)方法

当用户在 scrollView 上拖动时,此方法被调用 (BOOL)gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer 并且默认返回 NO

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
if (self.contentOffset.x > 0 && self.contentOffset.x <= self.contentSize.width - self.frame.size.width) {
//user is in middle of dragging the scrollView don't allow any other gestureRecognizer to respond
return NO;
}else{
//scrollView contentOffset is 0 and user is not dragging the scrollView so let other gestureRecognizer to respond
return YES;
}
}

关于ios - 禁用 UIScrollView 拖动事件到特定方向并将事件发送到 super,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18704244/

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