几个小时以来,我一直在努力解决最小的动画故障。我的代码成功地将 View 移出屏幕,然后将其动画返回。它获得了正确的 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
})
关于iOS 动画故障,Y 坐标问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36913680/