Answer the question
In order to leave comments, you need to log in
How to properly handle touch in subview Objective c?
There is the following hierarchy. The main view lies on self.view. -> there are 2 other views on it -> in one of these two there is another view . By tag, I caught the touch on the last view, but when I move it to another view, the touch stops working!
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event{
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self.view];
UIView *view = [self.view hitTest:point withEvent:event];
NSLog(@"%@",view);
NSLog(@"point %@",NSStringFromCGPoint(point));
if(view.tag == 2)
{
self.draggingView = view;
[self.view bringSubviewToFront:self.draggingView];
CGPoint touchPoint = [touch locationInView: self.draggingView];
self.touchOffset = CGPointMake(CGRectGetMidX(self.draggingView.bounds) - touchPoint.x,
CGRectGetMidY(self.draggingView.bounds) - touchPoint.y);
}else{
self.draggingView = nil;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question