【发布时间】:2015-04-02 14:59:00
【问题描述】:
我正在学习一个迷宫教程 (link),其中我通过以下代码为名为 ghost1 的 UIImageView 设置动画(代码位于文件 ViewController.h 的 viewDidLoad: 方法中):
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。当我按下按钮时, 游戏已显示,但动画不起作用。
你知道为什么以及如何纠正它吗?
【问题讨论】:
标签: xcode segue cabasicanimation quartz-core