title: NSView: setFrameOrigin and setFrameSize - what is causing inconsistent behaviour in this code?
body: <p>I have created a simplified example. I imagine if someone experienced runs this they will easily be able to explain this behaviour...</p>
  <p>In the example the addView button creates a new child subview each time it is pressed. These subviews should be the same each time one is generated but it is only when the third subview has been generated that I get the correct result. What is the reason for this?</p>
  <p>If you uncomment the repetition of the frame and bounds calls in the drawRect method you get the correct result on the second attempt - again I cannot explain  this behaviour.</p>
  <pre><code>import Cocoa
  
  class ViewController: NSViewController {
  
      let parentView = ParentView(frame: NSRect(x: 100, y: 10, width: 100, height: 400))
      let yMax = 400
      
      override func viewDidLoad() {
          super.viewDidLoad()
          self.view.addSubview(parentView)
      }
  
      @IBAction func addView(_ sender: Any) {
          
          let childView = ChildView(frame: NSRect(x:0, y: 0, width: 20, height: 20))
          self.parentView.addSubview(childView)
          
          for v in parentView.subviews {
              print(&quot;subview frame: &quot;, v.frame)
          }
          
      }
      
  }
  
  class ParentView: NSView {
      
      override func draw(_ dirtyRect: NSRect) {
          super.draw(dirtyRect)
          
          guard let context = NSGraphicsContext.current?.cgContext else {
              return
          }
          drawRect(ctx: context)
      }
      
      func drawRect(ctx: CGContext) {
          let parentFrameMarker = NSRect(x: 0, y: 0, width: 100, height: 400)
          ctx.addRect(parentFrameMarker)
          ctx.setStrokeColor(CGColor(red: 1.0, green: 0.0, blue: 0.0, alpha: 1.0))
          ctx.setLineWidth(1.0)
          ctx.strokePath()
      }
      
  }
  
  class ChildView: NSView {
      
      let controller = ViewController()
      
      
      override func draw(_ dirtyRect: NSRect) {
          
          guard let context = NSGraphicsContext.current?.cgContext else {
              return
          }
          
          let y = controller.yMax
          resizeView(y: y)
          drawRect(ctx: context, y: y)
          
      }
      
      func drawRect(ctx: CGContext, y: Int) {
          let width = 20
          let height = 40
  //      let currentY = y - height
  //
  //      let origin = CGPoint(x: 0, y: currentY)
  //      let size = NSSize(width: width, height: height)
  //      self.setBoundsSize(size)
  //      self.setFrameSize(size)
  //      print(&quot;new frame: &quot;, self.frame)
  //      print(&quot;new bounds: &quot;, self.bounds)
  //      self.setFrameOrigin(origin)
          
          let childFrameMarker = NSRect(x:0, y: 0, width: width, height: height)
          print(&quot;childFrameMarker size: &quot;, childFrameMarker.size)
          ctx.addRect(childFrameMarker)
          ctx.setStrokeColor(CGColor(red: 0.0, green: 1.0, blue: 0.0, alpha: 1.0))
          ctx.setLineWidth(2.0)
          ctx.strokePath()
          
      }
      
      func resizeView(y: Int) {
          let width = 20
          let height = 40
          let currentY = y - height
          let origin = CGPoint(x: 0, y: currentY)
          let size = NSSize(width: width, height: height)
          self.setBoundsSize(size)
          self.setFrameSize(size)
          self.setFrameOrigin(origin)
          print(&quot;new frame: &quot;, self.frame)
          print(&quot;new bounds: &quot;, self.bounds)
      }
      
  }
  </code></pre>