I'm a bit new to app development. In a viewController ( VPviewController ) i have the following code:
- (void) motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{
if (motion == UIEventSubtypeMotionShake){
[self startGame:nil];
}
}
In a different viewController ( VPgameViewController ) i have a different MotionShake event:
- (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];
}
}
}
When i'm in the VPgameView and i shake the Iphone it's also calling the startGame function which is in a different viewController shake event.
How can i stop this?
Sounds like you have to unsubscribe your VPViewController
from receiving the shake event notifications in its viewWillDisappear:
function.
Generally, if you want your viewController to receive certain event notifications only when visible you should subscribe to the notification in the viewWillAppear:
function and unsubscribe in the viewWillDisappear:
function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With