使用tvOS实现基本动画

时间:2015-09-28 00:18:08

标签: swift uiview tvos animatewithduration

我希望有人能够帮助我理解为什么我的tvOS动画没有运行。

在我的代码中,我有一个这样的函数:

func testAnimation() {
    clockLabel.alpha = 0.0
    UIView.animateWithDuration(1.0, animations: {
        self.clockLabel.alpha = 1.0
    })
}

我在testAnimation()内调用viewDidLoad(),但似乎没有动画。

我已经测试了几种不同类型的动画,从位置到不透明度,但似乎没有动画实际上在模拟器中运行。

目前,我的应用没有焦点。我试图做的就是加载一个空白的UIView,标签位于淡入的中间位置。

3 个答案:

答案 0 :(得分:4)

您试图在UILabel显示之前为其设置动画。将动画从viewDidLoad()移至viewDidAppear()

答案 1 :(得分:0)

我可以确认这种行为,因为这也适用于我。我所做的是设置延迟0.1(afterDelay :),它“足够好”

另一方面,DID实际工作的是为我的视图设置转换。例如。 (虽然objc):

    CGAffineTransform scaleTransform = CGAffineTransformMakeScale(0.5,0.5);
         [UIView animateWithDuration: 0.5 animations:^{
         _myView.transform = scaleTransform;
    } completion: nil]

也许这是tvOS中的一个错误

答案 2 :(得分:0)

尝试使用UIView Animation,就像这样(Swift):

clockLabel.alpha = 0
  UIView.animateWithDuration(0.5, delay: 0.0, options: .Linear, animations: {
    self.clockLabel.alpha = 1.0

  }, completion: { finished in
    // you may add some code here to make another action right after the animation end, or just delete this comment :)
  })

这对我们有用。

相关问题