6

我对应用程序开发有点陌生。在 viewController ( VPviewController ) 我有以下代码:

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

在不同的 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];
        }
    }
}

当我在 VPgameView 中并摇动 Iphone 时,它​​也会调用不同 viewController 摇动事件中的 startGame 函数。

我怎么能阻止这个?

4

1 回答 1

2

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

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

于 2012-11-21T19:26:51.013 回答