2014-02-21 39 views
0

我需要一个检测摇动的功能,而不必在每个viewController中添加- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event。 但是,当我将函数添加到appDelegate,运动未检测到。 我试过NSNotificationCenter无济于事。我有吨的viewControllers和将motionEnded方法添加到所有这些将是单调乏味...iphone检测整个应用程序的摇晃

任何想法?

回答

1

您可以在AppDelegate.window中添加 - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)事件。

ps: 子窗口UIWindow

+0

这工作 - 非常感谢! – Swissdude

0

创建一个BaseViewController,把你的震动检测方法放在那里,让每一个控制器继承它。