Re: Pin NSScrollView documentView to Upper Left AND Pin Scrolling to Upper left
Re: Pin NSScrollView documentView to Upper Left AND Pin Scrolling to Upper left
- Subject: Re: Pin NSScrollView documentView to Upper Left AND Pin Scrolling to Upper left
- From: Keary Suska <email@hidden>
- Date: Tue, 7 Sep 2010 09:53:45 -0600
On Sep 4, 2010, at 11:25 AM, Keary Suska wrote:
> I am trying to have NSScrollView behavior similar to, well, every other implementation of a view in an NSScrollView (e.g. NSTextView, NSTableView, etc.).
>
> Pinning my view to the upper left is easy using the view-within-an-isFlipped-view, but when the NSScrollView is resized, the "visible point" is pinned to the lower right. This seems to be due to the flipped contentView.
>
> Notes: 10.4 only; final document view must be an IB-built view/no custom drawing needed or wanted.
>
> I can't find any info on handling proper resizing. Any assistance/leads are appreciated...
I guess all I needed was to step away from the problem for a while. Since there isn't a comprehensive solution that I could find, I will post it for posterity.
Taking the hint from http://www.cocoadev.com/index.pl?CenteringInsideNSScrollView the solution is thus:
1. Have your NSScrollView documentView set to a custom NSView subclass that:
a. returns YES from -isFlipped
b. overrides -setFrame: such that the frame size is constrained to being no smaller than the main subview
c. make sure the document view is anchored and resizable in all directions
NOTE: item (c) is just so the view will be resized when its superview is resized, which triggers the call to -setFrame:. If you don't implement it, scrolling will be pinned to the lower right as I describe in my original post. If you don't implement (b) (but you do (c)), you will never get scrollbars as the document view will always match the clipview size.
2. All of the content you want displayed in the scroll view is best held within a single (super)view. I think this is a more extensible approach, and works best when using code referenced at the above URL. Now here's the kicker that drove me insane: that main subview must be anchored BOTTOM and LEFT. Should be obvious, as its superview has a flipped coordinate system, but it didn't register for some reason.
I hope this helps someone down the road...
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
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