• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
drawRect runs twice, bounds are changed in between
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

drawRect runs twice, bounds are changed in between


  • Subject: drawRect runs twice, bounds are changed in between
  • From: N!K <email@hidden>
  • Date: Tue, 13 Jan 2015 21:25:09 -0800



In my simple test project, an NSBezierPath is created and stroked.

-(id)initWithCoder:(NSCoder*)coder{
_path = [[NSBezierPath alloc] init];
	create points
}

- (void)drawRect:(NSRect)dirtyRect {
	bounds = [self bounds];
    NSLog(@"\n\n               bounds: %@\n\n", NSStringFromRect(bounds));

    [[NSColor whiteColor] set];
    [_path   setLineWidth:07.0];    //default width = 1
    [_path stroke];

bounds = [self bounds];
NSLog(@"\n\n      emd         bounds: %@\n\n", NSStringFromRect(bounds));
}

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.

_path is not changed in either pass.

needsToDrawRect: is not used.

I’m using Xcode 6.1.1 in OSX 10.9.5.



I have not been able to find  a reason for this behavior. . I don’t know how to reveal the point between passes where bounds is actually changed. It does not happen in any other NSView projects of mine; drawRect runs only once in them

I would like to prevent the second pass, or at least prevent the bounds change between passes. I’m reluctant to try restoring bounds to its first value. I appreciate Ken Thomases’ warning in a previous subject not to change bounds in drawRect.

Can anyone explain why this happens? Is it possible to suppress it without destroying whatever good it does?

Thanks,

Nick




_______________________________________________

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


  • Follow-Ups:
    • Re: drawRect runs twice, bounds are changed in between
      • From: Quincey Morris <email@hidden>
    • Re: drawRect runs twice, bounds are changed in between
      • From: Jens Alfke <email@hidden>
  • Prev by Date: Re: NSThread
  • Next by Date: Re: drawRect runs twice, bounds are changed in between
  • Previous by thread: Re: NSThread
  • Next by thread: Re: drawRect runs twice, bounds are changed in between
  • Index(es):
    • Date
    • Thread