Post

Replies

Boosts

Views

Activity

Reply to What is changing the size of my window on first appearance?
After a lot more experimentation, I've determined that it is nothing to do with something running after windowDidLoad. The problem occurs when I calculate the size of the window content. Here's a version of the code: NSScrollView *scrollView = self.myScrollView; MyContentView *myContentView = [scrollView documentView]; NSSize contentSize = [[self.window contentView] bounds].size; NSSize viewSize = [scrollView contentSize]; CGFloat verticalPadding = contentSize.height - viewSize.height; CGFloat horizontalPadding = contentSize.width - viewSize.width; NSSize myContentSize = [myContentView bounds].size; myContentSize = [NSScrollView frameSizeForContentSize:myContentSize horizontalScrollerClass:[NSScroller class] verticalScrollerClass:[NSScroller class] borderType:NSLineBorder controlSize:NSControlSizeRegular scrollerStyle:NSScrollerStyleOverlay]; myContentSize.height += 1; myContentSize.width += 1; NSSize maximumSize = myContentSize; maximumSize.height += verticalPadding; maximumSize.width += horizontalPadding; The problem is that viewSize, the size of the visible portion of the scroll view, can have one of two different values, which differ by 24. It seems to be arbitrary which of the two values is provided. Thus the maximum size, which is then set as the window content size with setContentSize, varies by 24, dependent on nothing that I can see.
Topic: UI Frameworks SubTopic: AppKit Tags:
Feb ’24
Reply to What is changing the size of my window on first appearance?
There is actually some interaction with window restoration, which resets the size of the window after windowDidLoad. What is working is to delay the size calculation until after the window actually gets displayed (after restoration), by replacing [self calculateSize] (essentially the code above) at the end of windowDidLoad with this hack: dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self calculateSize]; }); This appears to point to a problem where the size of the various views is not always set correctly until the window has been displayed. However, I'd love to proved wrong and find out what is the actual cause.
Topic: UI Frameworks SubTopic: AppKit Tags:
Mar ’24
Reply to How to validate a property list has the right structure
As I said, it's a property list, so the only validation I get is that it is a well-formed property list. It's the validating the values that I'm stuck on. Is there something better than code like this? NSObject *name = dict[@"name"]; if (![name isKindOfClass:[NSString class]]) { // report failure } In Swift I would be using the as? operator, and I guess that this is the closest equivalent. (My memory only recalled the isa method, but further searching turned up isKindOfClass.)
Topic: App & System Services SubTopic: General Tags:
Feb ’25