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

前端 未结 8 993
悲&欢浪女
悲&欢浪女 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:37

    Yes it should 100% work in common case. I've just tried with test project and everything seems to be ok.

    I've created View-Based Application. Using Interface Builder put new UIView up to the present View. Then create new file with subclass of UIView and select just created class for my new view. (Interface Builder->Class identity->Class->MyViewClass)

    Add touches handler functions both for MyViewClass and UIViewController.

    //MyViewClass

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"myview touches");
    [self.nextResponder touchesBegan:touches withEvent:event];
    }
    

    //ViewController

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {  
      NSLog(@"controller touches");
    }   
    

    I see both NSLogs when press MyViewClass. Did you use Interface Builder and XIB file when loading your ViewController or set view programatically with loadView function?

提交回复
热议问题