我的应用程序具有NSImageView子类,具有拖放功能,框样式和悬停动画。但是我有一个我无法解决的问题。悬停动画包含在layer.transform比例中,一切都很好,但是聚焦环蒙版没有改变其比例,如我在下一张图片中所示:
Problem with transform animation and focus ring mask
我尝试了一个没有运气的覆盖drawfocusringmask():/
动画代码是这样的:
func animateOnHover(layer: CALayer, duration: CFTimeInterval, fromValue: CGFloat, toValue: CGFloat) {
// Set the anchorpoint to the center of the NSImageView and animates from there
let frame = layer.frame
let center = CGPoint(x: frame.midX, y: frame.midY)
layer.position = center
layer.anchorPoint = CGPoint(x: 0.5, y: 0.5)
//Set the animation
let scaleAnimation = CABasicAnimation(keyPath: "transform.scale")
CATransaction.begin()
scaleAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
scaleAnimation.duration = duration
scaleAnimation.fromValue = fromValue
scaleAnimation.toValue = toValue
layer.add(scaleAnimation, forKey: "scale")
CATransaction.commit()
layer.transform = CATransform3DMakeScale(toValue , toValue, 0)
}
macOS 10.11 迅捷3.2 XCode 8.2.1