Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Layer Backed Views and Flickering Controls

I have a window which contains an NSBox control. In that NSBox are several other controls, (popups, text fields, etc...)

I have two other NSBox's in the same NIB file that are filled with controls that I would like to swap out with the first under certain conditions. I would like this to happen with a nice cross fade effect, so I do the following:

In the NSWindowController's -awakeFromNib method:

[[self.myWindow contentView] setWantsLayer:YES];

In my method where I'm switching the views I use this code:

[[[self.myWindow contentView] animator] replaceSubview:previousView with:newView];

This works just fine, the views cross fade just as I would expect. The problem is that the controls on the views sometimes disappear for no apparent reason. It's not always the same views (though the NSPopUpButtons seem particularly prone to it), and they usually reappear when they have focus.

Do I have to make all of the controls layer backed as well?


Update: Wrapping the animation in explicit grouping did not make any difference. Turning on setWantsLayer in the Nib file also didn't make a difference, but what is interesting is that when I did so, the NSPopupbuttons vanish until their containing view is clicked on. Setting Layer's manually on the NSPopupbuttons didn't make a difference either.

It appears that others have had this problem, but I can't find any solutions posted:

http://www.cocoabuilder.com/archive/message/cocoa/2008/3/30/202691 http://www.cocoabuilder.com/archive/message/cocoa/2008/4/25/205134

like image 214
lfalin Avatar asked Oct 14 '22 18:10

lfalin


1 Answers

If a view is layer backed all its subviews will be layer backed, so you do not need to manually set them to be layer backed. I don't know if there is enough info to see what is going on here, but I would be curious if you get different behavior if you wrap the animation in an explict grouping:

[NSAnimationContext beginGrouping];
[[[self.myWindow contentView] animator] replaceSubview:previousView with:newView];
[NSAnimationContext endGrouping];

Also, is there a reason why you are calling setWantsLayer: in awakeFromNib instead of just setting it in the nib (there should be a checkbox in the NSView inspector).

like image 117
Louis Gerbarg Avatar answered Oct 18 '22 12:10

Louis Gerbarg