简体   繁体   中英

Touches method in UIViewController and UIView

I'm working on iPad app. My UIViewController contains only a custom UIView with a size of 500wx500h.

I implemented the touches methods both in the UIViewController and the custom UIView in order to call the UIViewController touches methods when we touch all around the custom UIView and call the custom UIView touches methods when we touch inside it.

UIViewController touchesMoved :

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    CGPoint point = [touch locationInView:self.view];

    NSLog(@"TEST"); // Added during edition
    if (!CGRectContainsPoint(self.drawingView.frame, point)) {
        NSLog(@"UIVIEWCONTROLLER");
    }

}

Custom UIView touches Moved :

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"CUSTOM VIEW");
}

When I'm touching the custom UIView moving my finger, CUSTOM VIEW is logged until I removed the finger on the screen. On the other hand, when I'm touching outside of the custom UIView, the UIVIEWCONTROLLER is called only one time in the touchesMoved method.

Am I missing something wrong ?

EDIT : I added a log in my UIViewController touchesMoved method. When I touch inside the custom view, it logs the TEST during all the touching phase. But when I touch outside, I get the same behaviour.

向视图添加ExclusiveTouch属性以禁用多点触摸

your view.exclusiveTouch=YES;

There is some likeliness that your self.view is intercepting touches and handling them, so they will not make it through to the view controller. You could try doing either of 2 things (or both) and see if it works:

  1. self.view.exclusiveTouch = NO;

  2. self.view.userInteractionEnabled = NO;

I would also try to call [super touchesMoved: touches withEvent: event];

Hope it helps.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM