【发布时间】:2017-02-27 00:49:23
【问题描述】:
我想确定动画期间 UIVIew 的中心位置(视图的中间点)是什么。带有 UIViewPropertyAnimator 的动画如下:
let animator = UIViewPropertyAnimator(duration: 10, curve: .easeInOut)
var circle : UIView!
circle = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 40.0, height: 40.0))
circle.layer.cornerRadius = 20.0
circle.backgroundColor = UIColor.blue
self.view.addSubview(circle)
animator.addAnimations {
circle.center = CGPoint(x: 100,y: 100)
//or any other point
}
animator.startAnimation()
如果我在动画期间打印 circle.center 属性,那么我得到的只是动画的目标位置,而不是真实位置。
Timer.scheduledTimer(withTimeInterval: 0.2, repeats: true, block: {
[weak self] (Timer) -> Void in
if let circleCenterPosition = self?.circle.center
{
print(circleCenterPosition)
}
})
在这个打印之后,我在控制台上看到了这个:
(100.0, 100.0)
(100.0, 100.0)
...
如何在动画过程中打印真实位置?
谢谢。
【问题讨论】:
-
你想达到什么目的?如果要将圆圈添加到视图的中心,可以这样做
circle.center = self.view.center -
我想知道动画期间我的圆圈的确切位置(CGPoint)是什么。如果我将 circle.center 位置打印到控制台,它将只显示开始 (0.0) 和结束位置 (100,100)。
标签: ios swift uiview swift3 uiviewpropertyanimator