2

I have two NSView subclasses:

  • DrawRectView just draws a background color using the drawRect method
  • LayerBackedView also draws a background color using layer backing

The following code snippet a resizing animation via click actions on the views:

@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)
}

The DrawRectView animates as expected, but the LayerBackedView does not. It just jumps to the next rect with any animation.

So how to bring the same animation to the layer-backed view?

Marc
  • 2,900
  • 3
  • 26
  • 40

0 Answers0