[英]Touch events of Scrollview in subview of UITableviewCell in iOS
[英]Passing touch events to uiimageview within a scrollview added as subview to view
我在视图中添加了一个scrollview和imageview。 当我触摸此图像视图时,我的滚动视图将滚动。 在我的滚动视图中,有很多图像视图具有单独编写的触摸事件。
这是视图层次结构
View
|
|
------- --------
| |
imageView1 scrollview
|
...........................
| | |.....|
imageviews2
Imageview1在外观上高于imagesview2。
而且,当我滚动滚动视图时,无法触摸滚动视图中的某些imageView,因为它位于视图中的imageview的后面。
每当触摸事件在imageview1后面时,如何将其传递给imageviews2。
您需要将touch事件传递给父视图范围之外的UIView。
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
// Convert the point to the target view's coordinate system.
// The target view isn't necessarily the immediate subview
CGPoint pointForTargetView = [self.targetView convertPoint:point fromView:self];
if (CGRectContainsPoint(self.targetView.bounds, pointForTargetView)) {
// The target view may have its view hierarchy,
// so call its hitTest method to return the right hit-test view
return [self.targetView hitTest:pointForTargetView withEvent:event];
}
return [super hitTest:point withEvent:event];
}
https://developer.apple.com/library/ios/qa/qa2013/qa1812.html
您需要UIView
并重写
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
在该子类中跳过imageView1。
您可以通过UIImageView
并将其实例化为该类的成员来实例化imageView1,并覆盖pointInside
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{ return NO; }
不要忘记在滚动视图上取消选中“延迟内容触摸”和“可取消的内容触摸”!
我希望这个答案可能对某人有用。 我没有使用hittest就做到了。
在scrollview中使用了所有子视图,并检查它是否为图像视图,并执行以下操作。
使用[view touchesBegan:touches withEvent:event]将touchevents传递到另一个视图; 我们还必须在touchesMoved和touchesEnded中编写相同的内容。
谢谢,
十余
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.