I can't figure out why this is happening, but I have a subclass of UIView that is added to my view controller's view.
productView = [[SKUProductView alloc]initWithFrame:CGRectMake(60,768, 700, 550)];
[self.view addSubview:productView];
The view starts offscreen and will animate onscreen on a pan gesture event.While the view is offscreen, it is receiving touch events outside its own frame. I have developed a work around by overriding the hitTest method in the subview to return a hitTest call to the superview if the touch event is outside its frame.
-(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;
}
but I'm wondering why would my subview receive touch events outside its own frame in the first place?
Why not using
CGRectContainsPoint(rect, point);
to determine if the touch point is inside the frame of view ?
To be sure, print on console the view frame with NSStringFromCGRect()
function so you can understand what's happening.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.