• 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: clearing NSView outside of drawRect:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: clearing NSView outside of drawRect:


  • Subject: Re: clearing NSView outside of drawRect:
  • From: "Michael Ash" <email@hidden>
  • Date: Thu, 11 Sep 2008 23:05:24 -0400

On Thu, Sep 11, 2008 at 5:09 PM, Chinh Nguyen <email@hidden> wrote:
> How do you clear an NSView when drawing outside of drawRect:?

Don't. Drawing outside of drawRect: is, essentially, wrong. There are
extremely rare cases where it makes sense, but in virtually all cases,
if you suddenly feel the urge to draw outside of drawRect:, you should
take this as a sign that you are making some kind of error.

> I added and positioned a custom view on top another view
> (addSubView:positioned:relativeTo:) that draws a complex image so that I can
> draw selections in my custom view without having to worry about redrawing my
> original image or using a cached image.  Inside my mouseDragged:
> implementation, I lock my custom view's focus, attempt to erase the view
> using fillRect with clearColor (which doesn't work), draw my selection, then
> unlock the focus.  When that didn't work (and I tried returning yes and no
> for isOpaque), I went ahead and just did a setNeedsDisplay:YES on my custom
> view and just drew the selection in drawRect:.  That works but there's a
> noticeable lag while the mouse is being dragged.

It's possible to do high-performance animation by using
setNeedsDisplay:. If you're getting noticeable lag then the problem is
not the use of drawRect:, the problem is that something that you're
drawing (or some other piece of code) is taking too long. Find out
what it is and stop it from taking so long, and you'll be good to go.

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

References: 
 >clearing NSView outside of drawRect: (From: Chinh Nguyen <email@hidden>)

  • Prev by Date: Re: Trying to compile an ObjectiveC and C++ program in XCode 3.1
  • Next by Date: Re: clearing NSView outside of drawRect:
  • Previous by thread: clearing NSView outside of drawRect:
  • Next by thread: Re: clearing NSView outside of drawRect:
  • Index(es):
    • Date
    • Thread