【问题标题】:viewDidAppear() running on every clickviewDidAppear() 在每次点击时运行
【发布时间】:2017-02-03 06:48:09
【问题描述】:

我正在尝试为两个文本字段和一个标签创建动画幻灯片。但是由于某种原因,每次您尝试单击文本字段时都会运行 viewDidAppear() 函数,从而导致它们继续动画。有人有什么想法吗?

这是我的函数代码:

override func viewDidAppear(animated: Bool)
{
    //Some Code here
    UIView.animateWithDuration(1.5, delay: 0.5,
                               usingSpringWithDamping: 0.3,
                               initialSpringVelocity: 0.5,
                               options: [], animations: {
                                self.Email.center.x += 475
                                self.Password.center.x -= 400
        }, completion: nil)

    UIView.animateWithDuration(2.0, delay: 2.0,
                               options: [],
                               animations: {
                                self.LoginButton.alpha = 1.0
        }, completion: nil)
    UIView.animateWithDuration(1.5, delay: 0.5,
                               usingSpringWithDamping: 0.3,
                               initialSpringVelocity: 0.5,
                               options: [], animations: {
                                self.LoginL.center.y += 100
        }, completion: nil)

}

【问题讨论】:

  • 尝试添加对 super.viewDidAppear(animated) 的调用。
  • 添加超级调用修复了它,谢谢!
  • 很高兴它有帮助,请接受答案并关闭票证。附言您可能需要检查新的UIViewPropertyAnimator API,因为它专为像您这样的情况而设计 - 与 alpha 和 frame 混在一起。

标签: swift viewdidappear


【解决方案1】:

我们发现问题出在 UIViewController 的生命周期 - 需要调用 super.viewDidAppear(animated)

【讨论】:

    【解决方案2】:

    尝试运行它 viewWillAppear,你的动画只会在你的屏幕第一次加载时运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多