What's the trick to pass an event to the next responder in the responder chain?

前端 未结 8 985
悲&欢浪女
悲&欢浪女 2020-12-05 14:44

Apple is really funny. I mean, they say that this works:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch* touch = [touches any         


        
8条回答
  •  攒了一身酷
    2020-12-05 15:26

    Had trouble with this, as my custom view was deeper in the view hierarchy. Instead, I climbed the responder chain until it finds a UIViewController;

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        // Pass to top of chain
        UIResponder *responder = self;
        while (responder.nextResponder != nil){
            responder = responder.nextResponder;
            if ([responder isKindOfClass:[UIViewController class]]) {
                // Got ViewController
                break;
            }
        }
        [responder touchesBegan:touches withEvent:event];
    }
    

提交回复
热议问题