xcode ios 6摇动动作从前一个视图调用IBaction

Wes*_*put 6 iphone xcode motion-detection ios4 ios6

我对应用程序开发有点新意.在viewController(VPviewController)中,我有以下代码:

- (void) motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{
    if (motion == UIEventSubtypeMotionShake){       
        [self startGame:nil];
    }   
}
Run Code Online (Sandbox Code Playgroud)

在另一个viewController(VPgameViewController)中,我有一个不同的MotionShake事件:

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{
    if(event.subtype == UIEventSubtypeMotionShake){
        if(count < 3 ){

            [self changeText:nil];
            AudioServicesPlaySystemSound(1016);
            count++;

         }else{

            count = 0;
            AudioServicesPlaySystemSound(1024);
            UIStoryboard *storyboard = self.storyboard;
            VPpoepViewController *shit = [storyboard instantiateViewControllerWithIdentifier:@"PoepViewController"];
           shit.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
           [self presentViewController:shit animated:YES completion:nil];
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

当我在VPgameView中并摇晃Iphone时,它还调用了startGame函数,该函数位于不同的viewController震动事件中.

我怎么能阻止这个?

kad*_*dam 2

听起来您必须VPViewController在其功能中取消订阅摇动事件通知viewWillDisappear:

一般来说,如果您希望 viewController 仅在可见时接收某些事件通知,您应该在函数中订阅通知viewWillAppear:并在viewWillDisappear:函数中取消订阅。