我有两个 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没有。它只是用任何动画跳到下一个矩形。
那么如何将相同的动画带入 layer-backed view 呢?