Reputation: 5960
I put the motionBegan:withEvent: method in my view controller to see if it would work, but it's not being called. In viewWillAppear
, I made the view controller the first responder, and return YES from canBecomeFirstResponder
.
This view controller is in the master pane of a split view, so maybe the first responder was changed before I shook the device.
But my real question is how can I have all motion events passed to a handler in my app delegate? Do I really have to have motionBegan:withEvent: methods in all view controllers or delegates to all first responders? Isn't there a way to events like this to flow up the responder chain without inserting code into each UIResponder? It seems that there would be, but I haven't put my finger on how to do this.
Upvotes: 0
Views: 1184
Reputation: 131426
What I've done in the pass is to create a category of UIWindow that implements a motionBegan method. In that motionBegan method, I broadcast a custom NSNotification. Then, anywhere in the application that wants motion events, just add an observer for your motion notification.
Since categories add methods to EVERY instance of an object, even system created windows get your motionBegan method, and do the right thing. It works beautifully.
Upvotes: 0
Reputation: 396
the easiest way is override -sendEvent:
in UIApplication
then you will have controll over all events
that you may use this class
int retVal = UIApplicationMain(argc, argv, @"myApplication", @"myAppDelegate");
another solution is make category or expand -viewWillAppear:
more info
Upvotes: 1