Issue #720
NSStatusItem
is backed by NSButton
, we can animate this inner button. We need to specify position
and anchorPoint
for button’s layer so it rotates around its center point
guard
let button = statusItem.button
else { return }
let animation = CABasicAnimation(keyPath: "transform.rotation.z")
animation.fromValue = 0
animation.toValue = CGFloat.pi * 2
animation.duration = 0.25
animation.repeatCount = 1
button.layer?.position = NSPoint(x: NSMidX(button.frame), y: NSMidY(button.frame))
button.layer?.anchorPoint = NSPoint(x: 0.5, y: 0.5)
button.layer?.add(animation, forKey: "rotate")