I’m having resizing issues, and I think it’s because I don’t really know enough about frames and bounds.
I have a custom view within a scroll view, which fills the window. When I resize the window, I want the custom view to stay where it is, slowly getting covered/uncovered by the window in the place that the mouse is dragging.
What really happens is the custom view stays anchored to the lower left corner of the scroll view, so that if I make the window shorter, the custom view slides up to keep its lower left corner touching the scroll views corner.
How do I resize the window without moving a particular view?
The
frameis the area that the view will occupy within its parent. Theboundsis the section of the view that will be drawn within its frame. So 99.99% of the time that the two differ at all, they have the samesizebut the bounds has a zero origin and the frame has a non-zero origin.That said, it sounds more like you’re confused about the coordinate system. OS X follows the graph paper convention of the origin being in the lower left hand edge of the screen. So your scroll view’s origin is in the lower left of the window, which results in that point being the anchor when you resize. The size of the scroll view’s frame and bounds changes but the origin doesn’t.
Assuming you want the top left to be anchored rather than the bottom left (?), possibly the easiest thing to do would be to subclass
NSScrollViewand override- setFrame:to do appropriate arithmetic — grab the currentdocumentVisibleRect, work out what’s in the top left, allowsuperto set the new frame then callscrollToPointappropriately.