NSSplitView Problems
NSSplitView Problems
- Subject: NSSplitView Problems
- From: Richard Charles <email@hidden>
- Date: Wed, 3 May 2017 10:27:20 -0600
I have a vertical split view that does not use auto layout or constraints. The split view contains a custom subview that has the autoresizing mask set to NSViewWidthSizable.
During normal operation the user moves the split view divider which results in a collapsed subview. When the split view divider is repositioned to expose the subview, the size of the subview has been corrupted.
Apparently this is a well known historical problem caused when a superview collapses a subview. This issue has been extensively addressed by BWSplitView but RBSplitView but these projects are very old and have not been kept up to date.
After thinking about it and doing a little investigation it appears that the root cause of the problem is that the size of a view is never allowed to go negative when autoresizing. My guess is that if the size of a subview is allowed to go negative it would simply fix the issue.
In my subview custom class I implemented the following method override.
- (void)resizeWithOldSuperviewSize:(NSSize)oldSize
{
NSRect frame = self.frame;
NSRect superFrame = self.superview.frame;
NSAutoresizingMaskOptions mask = self.autoresizingMask;
if (mask == NSViewWidthSizable) {
CGFloat delta = superFrame.size.width - oldSize.width;
CGFloat x = frame.origin.x;
CGFloat y = frame.origin.y;
CGFloat w = frame.size.width + delta;
CGFloat h = frame.size.height;
self.frame = NSMakeRect(x, y, w, h);
}
else {
[super resizeWithOldSuperviewSize:oldSize];
}
}
This extremely simple solution seems to work perfectly. The subview collapses to zero and then the size goes negative. When the subview is uncovered, its size has not been corrupted and autoresizing works as expected.
So it appears that simply allowing the the size of a subview to go negative when autoresizing fixes an issue that has been around since the days of NeXTSTEP. So what am I missing?
--Richard Charles
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden