在appDelegate中没有调用motionEnded

时间:2013-03-05 10:44:58

标签: iphone ios

我想在整个应用中集成摇晃功能。所以我在appDelegate做所有事情。我需要推送一个viewController,我能够推进motionBegan,但我想做动作。是运动结束在视图控制器中工作,但在app委托中它没有被调用。 做为

- (void)applicationDidBecomeActive:(UIApplication *)application {
     [self becomeFirstResponder];
}
- (BOOL)canBecomeFirstResponder{
    return YES;
}

motionEnded not called

-(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");
    }
}

1 个答案:

答案 0 :(得分:1)

您基本上可以根据自己的需要为viewController注册applicationDidBecomeActiveNotification

例如,在viewController的{​​{1}}方法中,您可以注册通知

viewDidLoad

并在您的课程中实施此方法,每当您的应用程序变为活动状态时,您的[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMethod) name:UIApplicationDidBecomeActiveNotification object:nil]; 都会调用

myMethod

最后从dealloc方法

中的通知中取消注册viewController
-(void) myMethod(){
 // do your stuff
}
相关问题