这里不想说系统的动画操作,想说下POP这个框架的使用,真的不要太好用哦~~~
效果如下:
其实是闪动效果,包括透明度,边框颜色。
image.png
代码如下:
func animateButton() {
myButton.layer.borderWidth = 0.0
myButton.layer.borderColor = UIColor.red.cgColor
let opacity = POPBasicAnimation(propertyNamed: kPOPViewAlpha)
opacity?.toValue = NSNumber(floatLiteral: 0.6)
opacity?.duration = 1
opacity?.repeatForever = true
myButton.pop_add(opacity, forKey: "opacity")
// kPOPLayerBorderWidth
// kPOPLayerBorderColor
let width = POPBasicAnimation(propertyNamed: kPOPLayerBorderWidth)
width?.toValue = 4.0
width?.duration = 1
width?.repeatForever = true
myButton.layer.pop_add(width, forKey: "width")
let color = POPBasicAnimation(propertyNamed: kPOPLayerBorderColor)
color?.toValue = UIColor.yellow.cgColor
color?.duration = 1
color?.repeatForever = true
myButton.layer.pop_add(color, forKey: "color")
}
看代码是不是很简洁呀。需要注意的是配置kPOPLayerBorderWidth和kPOPLayerBorderColor动画的时候记得设置view的layer,不然就崩溃哦。再然后就是初始化设置初始值,不然没效果哈~~~
网友评论