如何让CAKeyframeAnimation在动画期间由用户进行交互?
问题描述:
CAKeyframeAnimation
不喜欢这样的:如何让CAKeyframeAnimation在动画期间由用户进行交互?
[UIView animateWithDuration:0.0 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
..
} completion:nil];
我们不能成立options:UIViewAnimationOptionAllowUserInteraction
。有没有人有一个好主意,使其在动画期间与用户进行交互?
答
我解决了在动画期间设置定时器更新帧的问题。
//Timer: To update the UI frame
Timer.scheduledTimer(timeInterval: 0.15, target: self, selector: #selector(updateFrame), userInfo: nil, repeats: true)
//Timer Selector
@objc func updateFrame(){
//getting the layer presentation bounds
let layer = "button, label...".layer.presentation()!
let point = CGPoint(x: layer.frame.origin.x, y: layer.frame.origin.y)
let size = CGSize(width: layer.frame.width, height: layer.frame.height)
// Update the UI element frame location
"ui element".frame = CGRect(origin: point, size: size)
}