• 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: needsDisplay and subviews
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: needsDisplay and subviews


  • Subject: Re: needsDisplay and subviews
  • From: Jeremy Hughes <email@hidden>
  • Date: Wed, 08 Mar 2017 23:25:40 +0000

The situation in which subviews were not being redrawn seems to have been a xib problem. After spending some time getting nowhere I decided to recreate the xib by taking a different xib (which used the same custom view) and cutting it down. This worked without any problems. Then I compared the two xibs in TextWrangler and found that the one which didn’t work had a view where “wantsLayer” was set to YES - and this corresponded to a “Core Animation Layer” checkbox in Interface Builder.

I didn’t intentionally select this checkbox, and I didn’t originally look at this pane (View Effects) when I was trying to spot differences between the view that worked and the view that didn’t. But in my first attempt at creating this xib (where the problem occurred) I copied and pasted a view from another xib, whereas in my second attempt I duplicated the entire xib and modified it - so maybe the checkbox property was set as a side effect of copying and pasting.

One other strange behaviour with the problem xib occurred when I added some debugging code to try and find out why the subview wasn’t being redrawn:

	view.needsDisplay = true
	print("view.needsDisplay: \(view.needsDisplay)”)

and this consistently printed “ view.needsDisplay: false” after view.needsDisplay had been set to true. Despite this, “draw” (= drawRect in ObjC) was being called for “view” - but not for view’s subviews.

My conclusion (for now) is that “needsDisplay” causes subviews to be redrawn - except when “wantsLayer” has been set to true.

Does that make sense?

Jeremy

--

> On 8 Mar 2017, at 17:12, Jeremy Hughes <email@hidden> wrote:
>
> Thanks - that seems reasonably clear, and it agrees with what I previously thought, but I’ve got a situation where it doesn’t seem to be happening.
>
> There are contradictory opinions on Stack Overflow:
>
> http://stackoverflow.com/questions/8718290/setneedsdisplay-and-subviews
> http://stackoverflow.com/questions/11480341/setneedsdisplay-does-not-trigger-drawrect-in-subviews-as-expected
>
> Jeremy
>
> --
>
>> On 8 Mar 2017, at 17:01, Ben Kennedy <email@hidden> wrote:
>>
>>
>>> On 08 Mar 2017, at 8:46 am, Jeremy Hughes <email@hidden> wrote:
>>>
>>> If needsDisplay is set to true for an NSView, does that also cause subviews to be redrawn?
>>
>> Admittedly I've been mostly doing iOS development for the last several years and barely any Mac lately, but, according to the current docs:
>>
>> needsDisplay: "The displayIfNeeded methods check the value of this property to avoid unnecessary drawing, and all display methods set the value back to false when the view is up to date."
>>
>> display(): "Displays the view and all its subviews if possible, invoking each of the NSView methods lockFocus(), draw(_:), and unlockFocus() as necessary."
>>
>> Thus, it seems to follow that so long a custom view's display() calls super, then all of its subviews should also be drawn when its needsDisplay is true.
>>
>> What sort of contradictions are out there?
>>
>> b
>>
>


_______________________________________________

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: needsDisplay and subviews
      • From: Quincey Morris <email@hidden>
References: 
 >needsDisplay and subviews (From: Jeremy Hughes <email@hidden>)
 >Re: needsDisplay and subviews (From: Ben Kennedy <email@hidden>)

  • Prev by Date: Re: Unicode filenames with Apple File System and UIManagedDocument
  • Next by Date: Re: needsDisplay and subviews
  • Previous by thread: Re: needsDisplay and subviews
  • Next by thread: Re: needsDisplay and subviews
  • Index(es):
    • Date
    • Thread