gpt4 book ai didi

iphone - xcode ios 6 摇动运动从以前的 View 调用 IBaction

转载 作者:行者123 更新时间:2023-12-03 18:46:24 27 4
gpt4 key购买 nike

我对应用程序开发有点陌生。在 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: 函数中接收摇动事件通知。

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

关于iphone - xcode ios 6 摇动运动从以前的 View 调用 IBaction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13496318/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com