Re: Panning a View
Re: Panning a View
- Subject: Re: Panning a View
- From: "I. Savant" <email@hidden>
- Date: Tue, 28 Jul 2009 14:05:54 -0400
On Jul 28, 2009, at 1:56 PM, Kyle Sluder wrote:
No, you must not do this.
...
So why would you think to do it in -drawRect:? Do it in
-awakeFromNib, or -[NSWindowController windowDidLoad], or -[NSDocument
windowControllerDidLoadNib:]. These are the places to do post-nib
loading setup.
It might be more helpful to explain why this isn't a good idea ...
Several things to consider:
1 - The -drawRect: method is supposed to be kept as lightweight as
possible because it could be called many times.
2 - What happens if something else causes your view's frame to be set
(which may cause the system to call -drawRect:, which may call your
frame setter, which calls -drawRect:...)?
)
... those are off the top of my head but aren't necessarily "must
nots", just "probably shouldn'ts". Leopard introduced -(void)
viewWillDraw for last-minute adjustments. If handled correctly,
performance may not be an issue at all and cycles can be avoided.
It's better, though, to implement a -sizeToFit method and call it
once when the view is created (or it's given its contents to display).
That's just better design.
If I'm missing something that's an absolute "must not", Kyle, I
welcome the insight.
--
I.S.
_______________________________________________
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