motionDefined未在appDelegate中调用
问题描述:
我想整合应用程序中的摇动功能。所以我正在做一切在AppDelegate。我需要推一个viewController,我可以推动motionBegan,但我想要做motionEnded。 yes motion motion在视图控制器中工作,但在应用程序委托中它没有被调用。 做的motionDefined未在appDelegate中调用
- (void)applicationDidBecomeActive:(UIApplication *)application {
[self becomeFirstResponder];
}
- (BOOL)canBecomeFirstResponder{
return YES;
}
motionEnded不叫
-(void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if(event.subtype==UIEventSubtypeMotionShake){
NSLog(@"motionEnded called");
}
}
motionBegan称为
-(void) motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if(event.subtype==UIEventSubtypeMotionShake){
NSLog(@"motionBegan called");
}
}
答
你基本上可以注册viewController
为applicationDidBecomeActiveNotification
或任何根据您的需要
例如你的viewController
的viewDidLoad
方法,你可以注册它的通知
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(myMethod)
name:UIApplicationDidBecomeActiveNotification object:nil];
,并在你的类实现此方法,您myMethod
将调用每次你的应用程序将变得活跃
-(void) myMethod(){
// do your stuff
}
终于从注销的viewController通知dealloc方法
-(void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
发布通知可以帮助我猜 – nsgulliver 2013-03-05 10:48:19
我避难所ot那么多的通知,我尝试了applicationDidBecomeActivie中的addedObserver“DeviceShaken”,但没有收获 – 2013-03-05 12:11:49
你解决了你的问题吗?回答有用吗? – nsgulliver 2013-03-05 16:51:55