• 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
Re: Drawing in a NSView out side of drawRect
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Drawing in a NSView out side of drawRect


  • Subject: Re: Drawing in a NSView out side of drawRect
  • From: "Michael Ash" <email@hidden>
  • Date: Sat, 20 Dec 2008 00:19:37 -0500

On Fri, Dec 19, 2008 at 7:20 PM, David Alter <email@hidden> wrote:
> I want to draw in a NSView but not when drawRect is called.

Others have pointed this out, but I want to reiterate: no you don't.
Trying to draw outside of drawRect: will only lead to pain. (It is
useful, on rare occasions. You are not experiencing one of them.) Work
with the view machinery. Call -setNeedsDisplay:.

However, I'll also point out why your code currently doesn't work,
just for posterity:

>     CGContextRef myContext =
> (CGContextRef)[[NSGraphicsContext currentContext]graphicsPort];

Right now you're getting the current graphics context, which is purely
arbitrary. Nothing has set it yet, so you're getting whatever happened
to be hanging around.

>    [self lockFocus];

Now you lock focus, which sets the current context to the one for your
view. Since you grab the context before you set it, things don't work
very well.

Mike
_______________________________________________

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: Drawing in a NSView out side of drawRect
      • From: "David Alter" <email@hidden>
    • Re: Drawing in a NSView out side of drawRect
      • From: "David Alter" <email@hidden>
References: 
 >Drawing in a NSView out side of drawRect (From: "David Alter" <email@hidden>)

  • Prev by Date: Re: Newbie Question: implementing a stack
  • Next by Date: Re: getObjects:andKeys
  • Previous by thread: Re: Drawing in a NSView out side of drawRect
  • Next by thread: Re: Drawing in a NSView out side of drawRect
  • Index(es):
    • Date
    • Thread