2015-04-02 74 views
0

由於下面的代碼(代碼位於ViewController.h文件的viewDidLoad:方法中),我正在執行一個迷宮教程(link),其中我爲名爲ghost1的UIImageView設置了動畫:CABasicAnimation在暫停後不起作用

CGPoint origin1 = self.ghost1.center; 
CGPoint target1 = CGPointMake(self.ghost1.center.x, self.ghost1.center.y-124); 

CABasicAnimation *bounce1 = [CABasicAnimation   

animationWithKeyPath:@"position.y"]; 
bounce1.fromValue = [NSNumber numberWithInt:origin1.y]; 
bounce1.toValue = [NSNumber numberWithInt:target1.y]; 
bounce1.duration = 2; 
bounce1.autoreverses = YES; 
bounce1.repeatCount = HUGE_VALF; 

[self.ghost1.layer addAnimation:bounce1 forKey:@"position"]; 

在這一點上,它運作良好。現在,我想爲應用程序添加一個新的初始視圖(以便首先顯示菜單而不是直接顯示遊戲),並在此新視圖中按下「開始」按鈕時啓動遊戲。

我添加了按鈕和「show」類型的segue。當我按下按鈕, 遊戲顯示,但動畫不起作用。

你知道爲什麼以及如何糾正嗎?

回答

0

好,我只是在這裏找到一個解決方案:link

我不得不將代碼從viewDidLoad中招:viewDidAppear :.我不完全明白爲什麼,但它的工作原理。