Segues从几个区域调用不起作用

时间:2014-11-23 17:05:56

标签: ios objective-c animation segue

UIView animateWithDuration完成时,我用5种不同的方法调用segue。我发现如果我只调用一次segue(动画只有一个UIImageView)一切正常,但是通过调用多个这个错误出现:

Warning: Attempt to present <GameOver: 0x7ffc7b714280> on <Playing_Page: 0x7ffc7b7128b0> whose view is not in the window hierarchy!

完成块(所有动画都相同)

//In completion block
if (a!=b) {
    [self squareOneColour];
    [self squareOneMover];
}
if (a==b) {
    if (self.squareOne.hidden==NO) {
        [self performSegueWithIdentifier:@"gameOver" sender:self];
    }
}
//Conditions must be included in answer. The are unique to each animation

因此,当所有五个动画完成(并满足条件)时,它会调用segue 5次并产生错误(我很确定,因为我做了很多测试)

我想要的是Playing_Page在完成动画(并满足条件)时无错误地转换为GameOver。有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

您可以在每个动画的完成块中增加一个整数属性,并在该属性的重写setter中检查该值。在下面的示例中,该属性称为计数器,我有三个从按钮触发的动画。我只是显示一个按钮的代码,但完成块中的代码是相同的。

-(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;
    }];
}