我有两个NSView子类:
DrawRectView
只使用 drawRect 方法绘制背景色LayerBackedView
还使用图层支持以下代码片段通过视图上的点击操作调整大小动画:
@IBAction func clickDrawRectView(sender: NSClickGestureRecognizer) {
let height = drawRectView.frame.height * 1.2
let width = drawRectView.frame.width * 1.2
NSAnimationContext.runAnimationGroup({ (context) in
context.duration = 1.0
self.drawRectView.animator().frame = NSMakeRect(self.drawRectView.frame.origin.x, self.drawRectView.frame.origin.y, width, height)
}, completionHandler: nil)
}
@IBAction func clickLayerBackedView(sender: NSClickGestureRecognizer) {
let height = layerBackedView.frame.height * 1.2
let width = layerBackedView.frame.width * 1.2
NSAnimationContext.runAnimationGroup({ (context) in
context.duration = 1.0
self.layerBackedView.animator().frame = NSMakeRect(self.layerBackedView.frame.origin.x, self.layerBackedView.frame.origin.y, width, height)
}, completionHandler: nil)
}
DrawRectView 按预期动画,但 LayerBackedView 没有。它只是通过任何动画跳转到下一个矩形。
那么如何将相同的动画带到图层支持的视图?