title: How to smoothly zoom a view using Option+mouse scroll events
body: <p>I am trying to implement smooth zoom in and out using mouse scroll + Option key but can't figure out how to do this.</p>
  
  <p>Currently I have a ViewController that sets the frame size for the view to be zoomed, which is hosted in NSScrollView.</p>
  
  <p>However this results in a very shaky zoom experience - has anyone got any suggestions on how to achieve a nice smooth zoom when using the mouse scroll wheel</p>
  
  <pre><code>/// Capture mouse scroll wheel events and send to zoom function with mouse location
      /// so we can zoom in to the location
      override func scrollWheel(with event: NSEvent) {
  
          guard event.modifierFlags.contains(.option) else {
              super.scrollWheel(with: event)
              return
          }
  
          let dy = event.deltaY
          if dy != 0.0 {
  
              self.scrollZoom(dy, location: event.locationInWindow)
  
          }
      }
  
      func scrollZoom(_ delta: CGFloat, location: CGPoint) {
  
          zoom += delta * scrollZoomSpeedMultiplier
  
          let frame = caLayoutView.frame
          let newSize = CGSize(width: frame.width*zoom, height: frame.height*zoom)
          let newOrigin = frame.origin // Need to calculate the origin but for now just get smooth zoom to work
  
          caLayoutView.animator().frame = CGRect(origin: newOrigin, size: newSize)
  
      }
  </code></pre>