Search code examples
iosobjective-cuitabbarcontrolleruievent

Detecting shake gesture by multiple view controllers


I need to detect shake gesture in iOS. I have done the usual stuff and it works perfectly fine. The thing is I have multiple view controllers in UITabBarController and I wish each of them to detect the shake gesture.

When shaking in any of the view controller , I get switched to a particular tab. The problem is if I shake in one view controller and try to shake in other controller the gesture is not detected unless some action is performed in that controller.

I know I need to set becomeFirstResponder but I need to know how can this property be set to the current tab of the UITabBarController so that the shake gesture is recognised by all tabs.


Solution

  • Write the code for detection (usually via a notification observer for shake) in a base view controller and and all the controller will subclass from this. Now you can write the code to move the particular tab in this base controller.

    Problem solved.