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
xcode swift nsview nsdocument


source to share


No one has answered this question yet

Check out similar questions:

6
Autoresistive behavior of NSView
4
Cocoa: stop key view loop in custom NSView
1
Drawing "NSView" to custom view - how? Am I the right fit?
1
NSDocument: how to save and restore document window position?
1
NSDocument - setting a reasonable starting location for a window
1
NSView embedded in NSScrollView does not redraw sequentially
1
NSView inside NSScrollview won't resize
0
How to move NSImageView inside NSView in cocoa?
0
Cocoa autodetect problem - NSTextView inside custom NSView
0
Is it possible to automatically resize NSView in swift?



All Articles
Loading...
X
Show
Funny
Dev
Pics