Carter
Carter

Reputation: 4758

El Capitan broke my NSView animations

I have a Mac app that uses a NSAnimationContext animation grouping to animate one NSView offscreen and another NSView onscreen. Prior to beginning the animation grouping I position the offscreen NSView in the position that I want it to originate from when it animates onscreen.

Under Yosemite and earlier versions this worked perfectly but under El Capitan it is as if the NSView never gets positioned in the start position that I specify so it animates onscreen from the wrong direction.

//Position offscreen view at correct starting point.
offscreenView.frame = STARTING_OFFSCREEN_RECT;

//Create animation grouping
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:animationDuration];
[[NSAnimationContext currentContext] setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[NSAnimationContext currentContext] setCompletionHandler:^{
    /*
    Do cleanup stuff here
    */
}];

//Move the views
onscreenView.frame = ENDING_OFFSCREEN_RECT:
offscreenView.frame = ENDING_ONSCREEN_RECT;

//End Grouping
[NSAnimationContext endGrouping];

I've debugged this to the best of my ability and it appears to me that the setting of offscreenView's frame at the very beginning is not actually occurring.

Does anybody know what I'm doing wrong?

Upvotes: 4

Views: 453

Answers (1)

corro
corro

Reputation: 363

I had very similar problem - offscreenView sometimes starts from the wrong position.
The offscreenView.layer appears to be messed up.

I fixed it by adding the following to my clean-up code:

onscreenView.layer = nil;

so that the next time the offscreenView is animated it will start with clean layer.
Or maybe in your case reset the layer before starting the animation:

offscreenView.layer = nil;

//Position offscreen view at correct starting point.
offscreenView.frame = STARTING_OFFSCREEN_RECT;

//Create animation grouping
...

NOTE:

In my animation I add the offscreenView every time to the superView:

//Position offscreen view at correct starting point.
offscreenView.frame = STARTING_OFFSCREEN_RECT;

[superView addSubview:offscreenView];

//Create animation grouping
...

And in the clean-up code I remove the onscreenView as well:

[onscreenView removeFromSuperview];
onscreenView.layer = nil;

Upvotes: 1

Related Questions