iphone - UIScrollView 将触摸发送到 subview

标签 iphone ios ipad uiview uiscrollview

注意:我已经阅读了一些关于 UIScrollView 向 subview 发送触摸的问题(包括 this,虽然我投了赞成票,但它没有按我的预期工作不再)。

我有什么:我有一个 UIScrollView,里面有一个自定义 UIView(我们称它为 A)它涵盖了整个 UIScrollView。我还可以将其他自定义 UIViews 放入 A

在我这样做的代码上:

[scrollView setDelaysContentTouches:YES];
scrollView.canCancelContentTouches = NO;

发生了什么:目前我唯一的问题是,如果我想在 A 中移动一个 subview ,我必须触摸它,等待,然后移动它。完全符合说明 here :

Now, the behaviour changes depending on the "length in time" of the first touch on the UIView. If it's short, then the relative dragging is managed as it was a scroll for the UIScrollView. If it's long, then I'm getting the touchesMoved: events inside my UIView.

我想要的:A 内的 subview 应该始终获得优先权,我不应该触摸和等待。如果我触摸 A 而不是它的 subview ,我希望 UIScrollView 接收触摸,比如平移和四处移动(contentSize 是比 frame 大)。


编辑 1.0

我在通用 UIScrollView 中使用此 A View 的唯一原因是因为我希望能够放大/缩小 A View 。所以我正在做以下事情:

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return customView; // this is the A view
}

一开始我在 UIScrollView 中没有 A View ,我唯一做的就是添加 A 作为我的 UIViewController 的 Root View 的 subview ,一切顺利。 如果有其他方法可以启用放大/缩小,我会很乐意接受这个答案。

最佳答案

注意:感谢大家的贡献,特别是 Aaron Hayman。

我能够通过对我拥有的 UIScrollView 子类执行以下操作来解决这个问题:

-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
   CGPoint pointOfContact = [gestureRecognizer locationInView:self];

    // The view with a tag of 200 is my A view.
    return (![[self hitTest:pointOfContact withEvent:nil] isEqual:[self viewWithTag:200]]);
}

关于iphone - UIScrollView 将触摸发送到 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11947797/

相关文章:

ios - 关于UITableView如何复用cell的几个问题

ios - 在两个 UINavigationController 之间导航

ios - 尝试使用 AV Foundation 捕获静止图像时不断出现 "inactive/invalid connection passed"错误

iphone - Xcode 退出代码 1 - 重复符号

iphone - 如何知道 UITableView 以何种方式滚动

iphone - 手势识别器,奇怪的行为(乘数效应)iOS

iphone - 如何根据时间延迟停止主线程序列?

iphone - NSMutableURLRequest 偶尔出现 "no boundary"错误

ios - iCarousel viewForItemAtIndex 使用自定义 UIView 重新使用第一个加载的图像

ios - Objective C - 点击手势计数