Ios 从几个不工作的区域调用的分段
当Ios 从几个不工作的区域调用的分段,ios,objective-c,animation,segue,Ios,Objective C,Animation,Segue,当UIView animateWithDuration完成时,我有一个segue被5种不同的方法调用。我发现,如果只调用一次segue(仅为一个UIImageView设置动画),一切正常,但通过调用多个,会出现以下错误: Warning: Attempt to present <GameOver: 0x7ffc7b714280> on <Playing_Page: 0x7ffc7b7128b0> whose view is not in the window hierar
UIView animateWithDuration
完成时,我有一个segue被5种不同的方法调用。我发现,如果只调用一次segue(仅为一个UIImageView
设置动画),一切正常,但通过调用多个,会出现以下错误:
Warning: Attempt to present <GameOver: 0x7ffc7b714280> on <Playing_Page: 0x7ffc7b7128b0> whose view is not in the window hierarchy!
因此,当所有五个动画都完成(并满足条件)时,它会调用segue 5次并创建错误(我非常确定,因为我做了很多测试)
我想要的是,当动画(并满足条件)完成时,
Playing_Page
可以毫无错误地过渡到GameOver
。有什么帮助吗?您可以在每个动画的完成块中增加一个整数属性,并在覆盖的setter中检查该属性的值。在下面的示例中,该属性称为counter,我有三个由按钮触发的动画。我只是显示了一个按钮的代码,但是完成块中的代码是相同的
-(void)setCounter:(NSInteger)counter {
_counter = counter;
if (_counter == 3) {
NSLog(@"All three animations are done");
// do your segue here
}
}
- (IBAction)leftButton:(id)sender {
self.leftCon.constant = 300;
[UIView animateWithDuration:5 animations:^{
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
self.counter +=1;
}];
}
在
Playing_Page
中的squareOneMover
的完成块中,您在何时何地调用performsguewithidentifier
。当动画完成@Mitley时,它会执行segue。我的意思是,在哪个父方法中,viewDidLoad
,iAction
,etcA方法称为iAction
,当然你会得到那个错误,因为一旦你调用了preformSegue,当你调用其他4次时,播放页面就不再在屏幕上了。你需要改变你的逻辑,这样你只需要调用一次。如果你不了解更多关于你的5部动画的知识,你很难建议你如何去做。谢谢你的回答,这真是太棒了。除非您排除了a
和b
。我忘了在问题中写下(对不起),它们对于每个动画都是不同的。这就是为什么我的情况如此困难的原因,因为另一个if语句将第一个if语句拆分为5个位置,以便分段called@Minestrone-好吧,如果你需要更多的帮助,你需要编辑你的问题来提供更多的信息,就像我在评论中问的那样。你所说的“每个动画都不同”是什么意思?
-(void)setCounter:(NSInteger)counter {
_counter = counter;
if (_counter == 3) {
NSLog(@"All three animations are done");
// do your segue here
}
}
- (IBAction)leftButton:(id)sender {
self.leftCon.constant = 300;
[UIView animateWithDuration:5 animations:^{
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
self.counter +=1;
}];
}