iOS 动画故障,Y 坐标问题

iOS animation malfunctioning, Y-Coordinate Problems

几个小时以来,我一直在努力解决最小的动画故障。我的代码成功地将视图移出屏幕,然后将其动画化。它使 x 坐标正确,但 Y 轴具有我不理解的行为。这是代码:

func listTrans_slideIn (slideFrom: String) {
    //var newFrame = tableView.frame
    tableView.frame.origin.x = 1000
    //tableView.frame.origin.y = 100
    print("Table pushed to side")

    UIView.animateKeyframesWithDuration(1.375 /*Total*/, delay: 0.0, options: UIViewKeyframeAnimationOptions.CalculationModeLinear, animations: {
        UIView.addKeyframeWithRelativeStartTime(0.0, relativeDuration: 1/1, animations:{
            self.tableView_toTLG_Top.constant = 130
            self.tableView_toSV_Left.constant = 0
            self.tableView_toSV_Right.constant = 0
            self.setupView()

            //newFrame.origin.y = self.hdrBox.frame.height+50
            //newFrame.origin.x = 0
            //self.tableView.frame = newFrame

            self.tableView.layoutIfNeeded()
        })
        },
        completion: { finished in
            if (!finished) { return }

        })
}

奇怪的是,如果我在动画关键帧中输入正确的 y 坐标,它会变得过高,但随后会稳定在正确的坐标上。如果我输入的 y 坐标太低,它会以正确的高度出现,但随后会变得太低。

如您所见,我尝试过使用框架和约束。我尝试更改将其移出屏幕的高度,但这似乎没有效果。

有人知道为什么我花了半天时间才看到这个错误吗?

你能试试这样吗:

  // Use the same value here and below, it moves it out of the screen
        self.tableView.center.y -= 500

 UIView.animateWithDuration(1.0, animations: { () -> Void in

       // Then it comes back 
           self.tableView.center.y += 500
    })

原来是操作顺序问题。该解决方案要求我将动画移动到 viewDidAppear 中。

其他说明:

  • 为了使动画看起来尽可能流畅,请考虑关闭 segue 的动画。
  • 还要确保您是 运行 主线程中的 segue 调用和动画,以便一切顺利且没有延迟