N
N
Nikolaymac2016-09-13 09:18:59
Objective-C
Nikolaymac, 2016-09-13 09:18:59

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

1 answer(s)
B
briahas, 2016-09-22
@briahas

So what's with the problem? Decided?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question