Re: drawRect runs twice, bounds are changed in between
Re: drawRect runs twice, bounds are changed in between
- Subject: Re: drawRect runs twice, bounds are changed in between
- From: Jens Alfke <email@hidden>
- Date: Tue, 13 Jan 2015 22:50:33 -0800
> On Jan 13, 2015, at 9:25 PM, N!K <email@hidden> wrote:
>
> A breakpoint at the end of drawRect shows that it runs twice. After the second pass, the view appears, as it should.
> Between passes, bounds is changed somehow, as shown by NSLog at the start and end of drawRect.
> Since this will upset code that I will add later, I’d like to stop this.
The view's being resized, probably as part of view layout. Ideally AppKit shouldn't draw the view before it gets to its final size, but maybe this is part of an animation, or maybe it's something that hasn't been optimized 100% in AppKit.
In general, you should not make assumptions about when and how often -drawRect: will be called. That's up to AppKit. Your job is just to draw the view when you're told to.
You haven't said why the bounds change will upset your code; is the view being changed to the wrong size? That would be an actual problem, but it isn't related to being drawn multiple times. You'd need to look at the view constraints in your window to diagnose that.
—Jens
_______________________________________________
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