gpt4 book ai didi

objective-c - 用 2 根手指捏合时禁用 UIScrollView 中的平移

转载 作者:搜寻专家 更新时间:2023-10-30 20:25:38 26 4
gpt4 key购买 nike

我想在检测到第二次触摸后停止滚动,并用我自己的捏合手势处理触摸。我在 ScrollView 中试过这个:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if(event.allTouches.count > 2)self.panGestureRecognizer.enabled = NO;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if(event.allTouches.count > 2)self.panGestureRecognizer.enabled = YES;
}

但它不起作用。

试试这个:

scroll.panGestureRecognizer.maximumNumberOfTouches = 1;

但是没有

最佳答案

我找到了解决方案。我重新定义了 UIScrollView,并添加:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}

并禁用\启用平移手势:

if(pinch.state == UIGestureRecognizerStateBegan) scroll.panGestureRecognizer.enabled = NO; 
if(pinch.state == UIGestureRecognizerStateEnded) scroll.panGestureRecognizer.enabled = YES;

现在我的捏合手势起作用了。

关于objective-c - 用 2 根手指捏合时禁用 UIScrollView 中的平移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13988532/

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