我的应用程序结构有点复杂,但遇到了一些小问题:
因此,首先要考虑的是视图层次结构:
|- UICollectionView (horizontal scrolling)
-> UICollectionViewCell
|-> UIScrollView A (PagingEnabled = YES, vertical scrolling only)
|-> UIImageView = page 1
|-> UIScrollView B (PagingEnabled = NO, vertical scrolling only) = page 2
|-> UIView (content...)
问题是,当我在UIScrollView A上滚动以显示第2页时,将忽略第一个滚动到UIScrollView B底部的滚动,根本没有滚动,但是第二个滚动具有正确的行为。
我认为这是一种“聚焦”问题,但是我不知道如何使它正常工作。
关于如何使第2页上的第一次触摸正确的UIScrollView有任何线索?
你尝试过hitTest:withEvent:
方法吗?此方法可帮助您选择应该接受触摸的视图。
例如,您可以继承UIScrollView A的类UIScrollView
并将其设置为刚创建的新类。将以下代码添加到此自定义类中,即可让您将触摸效果传递给它的子视图的第一个UIScrollView
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
for (UIView *subView in self.subviews) {
// Convert the point to the subView's coordinate system.
CGPoint pointForTargetView = [subView convertPoint:point fromView:self];
if (CGRectContainsPoint(subView.bounds, pointForTargetView)) {
// Calling subView's hitTest:withEvent get the right view
return [subView hitTest:pointForTargetView withEvent:event];
}
}
UIView *hitView = [super hitTest:point withEvent:event];
// // Uncomment if you want to make the view 'transparent' to touches:
// // meaning the parts of the view without any subview will deliver the touch
// // to the views 'behind' it
// if (hitView == self) {
// return nil;
// }
return hitView;
}
欲了解更多详细信息,请WWDC -高级Scrollviews和触摸操作技术(下午3点左右是这个问题开始的位置)。
另外,还要感谢蒂姆·阿诺德(Tim Arnold)提供的线索。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句