Skip navigation.
 
mlRe: keeping view's bounds fixed
FROM : Ken Thomases
DATE : Wed Jan 30 05:51:14 2008

On Jan 28, 2008, at 10:38 PM, Nathan Vander Wilt wrote:

> I have a view whose bounds I want to keep, so that the
> visible area runs from (-180,-90) to (180,90) in the
> view's coordinate system. The view needs to autoresize
> in all ways, so that its edges are each a fixed
> distance away from the window/superview.
>
> In my initWithFrame: method, I call [self
> setBounds:NSMakeRect(-180, -90, 360, 180)]; This makes
> the intial drawing work as intended, but as soon as
> the window (and view) are resized, the bounds get
> updated to the match the new frame size.
>
> I tried resetting the bounds at the top of my
> drawRect: method, but that doesn't work if only for
> the simple reason that the "dirty" rectangle passed
> wouldn't get updated. (It also had other nasty side
> effects.)
>
> In
> http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaViewsGuide/WorkingWithAViewHierarchy/chapter_4_section_6.html
> ,
> it says "If the bounds rectangle of the view has not
> been explicitly set using one of the setBounds...
> methods, the view's bounds rectangle is automatically
> updated to match the new frame size."
>
> Since I *have* explicitly set the bounds rectangle,
> why is it still being automatically updated to match
> the frame's height/width? Where can I reset the
> bounds, so that they always are set to
> NSMakeRect(-180, -90, 360, 180) when my view's
> drawRect is called? The -viewDidEndLiveResize method
> will not work, because that message isn't passed when
> the window's zoom button is activated.


What is the framework using to reset the view's bounds?  I would 
expect it's just sending setBounds: to the view.  What happens if you 
override setBounds: to ignore the passed-in rectangle and always pass 
NSMakeRect(-180, -90, 360, 180) to super?

-Ken

Related mailsAuthorDate
mlkeeping view's bounds fixed Nathan Vander Wilt Jan 29, 05:38
mlRe: keeping view's bounds fixed Quincey Morris Jan 29, 06:30
mlRe: keeping view's bounds fixed Nathan Vander Wilt Jan 29, 07:42
mlRe: keeping view's bounds fixed Ken Thomases Jan 30, 05:51