我有一个函数,可以将UIImageView从一组坐标移动到屏幕另一侧的另一组动画。在动画期间,我想记录一下图像在哪里时的位置。当我像这样打一个电话时,我得到的是目标位置而不是当前位置:
var rippleImage = UIImageView()
//example animation block
UIView.animate(withDuration: 6, delay: 0.0, options: [.curveLinear, .allowUserInteraction], animations: {
self.rippleImage.frame = CGRect(x: (xaxis - 500) , y: (yaxis - 500) , width: (self.rippleImage.frame.width + 1000), height: (self.rippleImage.frame.height + 1000))
self.rippleImage.alpha = 0.1
}, completion: nil )
//sample button click function to capture location
@objc func pianoKeyButtonTapped(sender: UIImageView) -> [String] {
// get and animate current ripple
let currentRippleLocation = self.rippleImage.frame
print(currentRippleLocation)
}
在每种情况下,我都会得到相同的目标位置,如下所示:
(-342.5, 67.0, 1060.0, 1060.0)
最佳答案
https://stackoverflow.com/a/7625335/4503593转换为Swift 3代码:
presentationLayer-CALayer的属性,“提供
与当前图层的版本非常接近
正在显示”
let currentRippleLocation = rippleImage.layer.presentation().frame