【问题标题】:CABasicAnimation doesn't work after a segue转场后 CABasicAnimation 不起作用
【发布时间】: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


    【解决方案1】:

    好的,我刚刚在这里找到了解决方案:link

    我只需将代码从 viewDidLoad: 移动到 viewDidAppear:。我不完全明白为什么,但它确实有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-13
      • 2019-05-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多