Reputation: 2583
I have a background subview which just have grey color's, and got tiles on top of it which can be dragged. This is all happening in one view controller. The problem is that when I do a hit test and try to avoid the backgroundView, since the tiles are on top of that view, it still see's those coordinates and avoid the touches move event since I am returning nil.
Below is the code:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
for (UIView *view in self.subviews) {
//This checks if touches are within the region of the custom view based on its cordinates.
if (CGRectContainsPoint(view.frame, point)) {
NSLog(@"touched the boat view %f %f and %f %f",view.frame.origin.x, view.frame.origin.y, point.x, point.y);
if ([view isEqual:backgroundView]) {
return nil;
}
else
return view;
}
}
return nil;
}
If you can see I am verifying for the background view, but since my tiles are on of the background view, those are not being dragged based on my other logic. I have tried userInteractiveEnabled to No, but that doesn't seams to work. Any suggestions?
Upvotes: 1
Views: 137
Reputation: 8649
you should have a subclass of uiview and implement hitTest on this subclass :
@implementation EDPassTroughView
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
-(UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
UIView *hitView = [super hitTest:point withEvent:event];
if (hitView == self)
return nil;
else
return hitView;
}
@end
Upvotes: 1