iphone – xcode ios 6摇动动作从前一个视图调用IBaction
发布时间:2020-12-14 19:40:06 所属栏目:百科 来源:网络整理
导读:我对应用程序开发有点新意.在viewController(VPviewController)中,我有以下代码: - (void) motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{ if (motion == UIEventSubtypeMotionShake){ [self startGame:nil]; } } 在另一个viewController
我对应用程序开发有点新意.在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时,它还调用了startGame函数,该函数位于不同的viewController震动事件中. 我怎么能阻止这个? 解决方法
听起来你必须取消订阅你的VPViewController才能在其viewWillDisappear:function中接收摇动事件通知.
通常,如果您希望viewController仅在可见时接收某些事件通知,则应在viewWillAppear:function中订阅通知,并在viewWillDisappear:function中订阅取消订阅. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |