Set NSView / NSDocument Size

I am creating an application that is modeled after the Sketch sample program. I quickly rewrote Sketch (it was a great way to learn the language) and everything works fine.

However, in this application, I want the document to be a fixed size other than the default used by Sketch. So I set the size I want in the Interface Builder in the window and in the custom NSView in the ZoomingScrollView. I also set the fixed minimum and maximum in the window to the same values ​​and uncontrolled size.

The app opens the window at the correct size, but the document canvas is still the original size from the Sketch app. My window is wide and squat (landscape), and the document inside it is tall (vertical scroller active) and narrow (there is a gray void area to the right of the document canvas).

I tried to programmatically resize the custom NSView, but nothing happens. In fact, custom NSViews are happy to report that they are limited and that the size is the fixed size they should be.

override func awakeFromNib() {
    var f = self.frame; // If you set a breakpoint here f reports as 568x320 anyway
    f.size.width = 568;
    f.size.height = 320;
    self.frame = f;
    self.setFrameSize(f.size)
    self.setBoundsSize(f.size)
}

      

One hint I think is that the Sketch app does not resize the canvas when it tries to resize it, and if you resize its window and SKTGraphicView dimensions in the Interface Builder, you get the same behavior I see.

I feel like I am missing something very basic here!

+3


source to share





All Articles