有没有办法判断UIView是否在动画中?当我在视图对象移动时打印出来时,我注意到有一个"动画"条目:
search bar should end editing: <UISearchBar: 0x2e6240; frame = (0 0; 320 88); text = ''; autoresize = W+BM; animations = { position=<CABasicAnimation: 0x6a69c40>; bounds=<CABasicAnimation: 0x6a6d4d0>; }; layer = <CALayer: 0x2e6e00>>
Run Code Online (Sandbox Code Playgroud)
当动画停止并且我打印视图时,"动画"条目现在消失了:
search bar should end editing: <UISearchBar: 0x2e6240; frame = (0 0; 320 88); text = ''; autoresize = W+BM; layer = <CALayer: 0x2e6e00>>
Run Code Online (Sandbox Code Playgroud) 我试图动画UIImageView,然后在动画完成后隐藏图像视图.但是,在动画完成之前,imageview会被隐藏.我查看了类似的问题,他们建议在完成后实现动画监听器或在动画代码中执行.hidden代码但是我不确定如何在下面的shakeView()函数中影响它.
如何在动画完成后显示摇动动画并隐藏图像视图?
使用以下代码调用动画:
shakeView(image1!)
shakeView(image2)
image1!.hidden = true
image2.hidden = true
Run Code Online (Sandbox Code Playgroud)
动画功能本身如下所示:
func shakeView(iv: UIImageView){
var shake:CABasicAnimation = CABasicAnimation(keyPath: "position")
shake.duration = 0.1
shake.repeatCount = 2
shake.autoreverses = true
var from_point:CGPoint = CGPointMake(iv.center.x - 5, iv.center.y)
var from_value:NSValue = NSValue(CGPoint: from_point)
var to_point:CGPoint = CGPointMake(iv.center.x + 5, iv.center.y)
var to_value:NSValue = NSValue(CGPoint: to_point)
shake.fromValue = from_value
shake.toValue = to_value
iv.layer.addAnimation(shake, forKey: "position")
}
Run Code Online (Sandbox Code Playgroud)