Ios 子视图在父视图中接收其帧外的接触
我不知道为什么会发生这种情况,但我有一个UIView的子类,它被添加到我的视图控制器的视图中Ios 子视图在父视图中接收其帧外的接触,ios,uiview,parent-child,subview,Ios,Uiview,Parent Child,Subview,我不知道为什么会发生这种情况,但我有一个UIView的子类,它被添加到我的视图控制器的视图中 productView = [[SKUProductView alloc]initWithFrame:CGRectMake(60,768, 700, 550)]; [self.view addSubview:productView]; 视图在屏幕外启动,并将在平移手势事件中在屏幕上设置动画。当视图在屏幕外时,它在自己的帧外接收触摸事件。我已经开发了一种变通方法,在子视图中重写hitTest方法,以便在
productView = [[SKUProductView alloc]initWithFrame:CGRectMake(60,768, 700, 550)];
[self.view addSubview:productView];
视图在屏幕外启动,并将在平移手势事件中在屏幕上设置动画。当视图在屏幕外时,它在自己的帧外接收触摸事件。我已经开发了一种变通方法,在子视图中重写hitTest方法,以便在触摸事件超出其框架时向superview返回hitTest调用
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
//Test to determine if view is offscreen or if touch is outside its frame
if (self.frame.origin.y >= 768 || point.x > self.frame.size.width)
{
return [super hitTest:point withEvent:event];
}
else if (point.y < kSKU_SCROLLVIEW_Y_OFFSET)
{
return [_productTabBar hitTest:point withEvent:event];
}
return _productScrollView;
}
但是我想知道为什么我的子视图首先会在它自己的框架之外接收触摸事件 为什么不使用
CGRectContainsPoint(rect, point);
确定接触点是否在视野范围内
可以肯定的是,使用NSStringFromCGRect函数在控制台上打印视图框,这样您就可以了解发生了什么。您是在情节提要中还是在代码中设置UIPanGesture识别器?如果以编程方式进行,是否可以发布代码?