CATransition push without fade

风流意气都作罢 提交于 2019-12-03 09:45:24

问题


I'm making a navigation controller class for Mac OS X.

I want to replace the current view with a kCATransitionPush animation.
Like in this post:
Core Animation Tutorial - Wizard Dialog With Transitions

The CATransition is set up like this:

CATransition *transition = [CATransition animation];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
[self.view setAnimations:@{ @"subviews" : transition }];

However, when I replace the views, there is a fade animation, which is being automatically added.

[NSAnimationContext beginGrouping];
{
    [[self.view animator] replaceSubview:_currentViewController.view with:newViewController.view];
}
[NSAnimationContext endGrouping];

How can I do a push animation without the fading?


回答1:


The best way I've found to get smooth Core Animation transitions that works regardless of whether the view supports CA or not is to do the following:

  1. Create an image of the view you are trying to animate, using NSView -cacheDisplayInRect:toBitmapImageRep or a similar method
  2. Put that image in an NSImageView
  3. Layer back the image view, which will draw fine without glitches when layer backed
  4. Add the image view as a subview over the view that you are trying to transition
  5. Animate the image view frame using NSView's animator proxy
  6. Remove the image view once the animation has completed



回答2:


I suspect you're running into implicit animations - Core Animation will automatically animate layer property changes that happen outside of your own transactions.

There's a good summary of several methods for disabling these implicit animations in these two questions:

How to disable CALayer implicit animations?

Disabling implicit animations in -[CALayer setNeedsDisplayInRect:]

...and you can read more about implicit transactions in the Core Animation docs




回答3:


I think the transition from left transition includes a built-in fade. The IOS push transitions do.

If you don't want that, you might have to roll your own push transition using Core Animation. This would be easy in iOS with UIView animations. Sadly, there is not an equivalent in Mac OS. I wish Apple would go back and add view animations to Mac OS. I get spoiled using them in iOS, and then miss them when I work on Mac applications.




回答4:


Add below code

        CATransition *transition = [CATransition animation];
        transition.type = kCATransitionPush;
        transition.subtype = kCATransitionFromLeft;
        [transition setDuration:0.5];
        [self.view.layer addAnimation:transition forKey:kCATransition];


来源:https://stackoverflow.com/questions/14293684/catransition-push-without-fade

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!