Layer-backed NSView animation

2019-05-09 13:22发布

I have a certain NSView that I want to animate, but that NSView has a NSTableView inside which does not display correclty when the view is layer-backed (which in turn is nececessary to animate a view). So my answer was to make the view layer-backed right before animating, and then when the animation was done remove the layer, like this:

[animatingView setWantsLayer: YES];

[NSAnimationContext beginGrouping];

[[animatingView animator] animateSomething];

[[NSAnimationContext currentContext] setCompletionHandler: ^{
    [animatingView setWantsLayer: NO];
}];

[NSAnimationContext endGrouping];

However, with this code the view doesn't animate at all. I found that if I remove the [animatingView setWantsLayer: NO]; line it animates just right, but then the table view doesn't display correctly (see this question for an example of one of the problems).

So, my question is: how do I solve this? I want to animate a view, but I want tables to display properly, and this workaround doesn't work. And I don't get why...

1条回答
可以哭但决不认输i
2楼-- · 2019-05-09 14:18

Once you make NSView layer-backed it cannot be reverted.

I suggest you to try to make your NSTableView a sibling of the layer-backed view, not a child.

查看更多
登录 后发表回答