简体   繁体   English

有没有其他方法可以使用动画块来执行此动画?

[英]Is there an alternative way to perform this animation using animation blocks?

I'm currently performing a curl up animation by doing the following: 我正在通过执行以下操作来执行卷曲动画:

CATransition *animation = [CATransition animation];
animation.type = @"pageCurl";
animation.subtype = kCATransitionFromTop;
animation.fillMode = kCAFillModeForwards;
animation.duration = 1;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
[[self.view.window layer] addAnimation:animation forKey:nil];

This animation will simply perform a page curl animation but in the end you are left looking at the same view that you started out with. 此动画将简单地执行页面卷曲动画,但最后您将看到您开始使用的相同视图。 No REAL transition ever occurred. 没有真正的转变发生过。

Now using animation blocks I know you can do something to the effect of: 现在使用动画块,我知道你可以做一些事情的效果:

[UIView transitionFromView:self.view
                    toView:aNewView    // a view to transition to
                  duration:1 
                   options:UIViewAnimationTransitionCurlUp|UIViewAnimationOptionCurveEaseIn
                completion:NULL];

However, using animation blocks you are transitioning to a new view, aNewView , which is different from the CATransition animation above which reuses the same view (no real transition ever occurs). 但是,使用动画块可以转换到新视图aNewView ,它与上面重复使用同一视图的CATransition动画不同(不会发生真正的转换)。 The problem with the animation block is that you have to actually create the new view to transition to which is cumbersome in my case because the view is rather complicated and I'd rather not create a UIView subclass. 动画块的问题在于你必须实际创建新视图以转换到我的情况下很麻烦,因为视图相当复杂,我宁愿不创建UIView子类。

Is there a way to perform the above CATransition animation using animation blocks while getting around the difficulties of having to rebuild a view or create a custom subclass? 有没有办法使用动画块执行上述CATransition动画,同时解决重建视图或创建自定义子类的困难?

Ok - so I figured it out for anyone who is interested. 好的 - 所以我想对任何有兴趣的人都知道了。 It's actually super simple. 它实际上非常简单。 You can simply use the method: transitionWithView:duration:options:animations:completion: 您只需使用以下方法: transitionWithView:duration:options:animations:completion:

For example: 例如:

[UIView transitionWithView:self.view
                  duration:1
                   options:UIViewAnimationOptionTransitionCurlUp|UIViewAnimationCurveEaseIn
                animations:^{ // do anything you want here } 
                completion:NULL];

That's it. 而已。 This will show a transition animation back to the same view. 这将显示返回到同一视图的过渡动画。 You can make any changes you want to the new view (maybe display some new text, whatever...) in the animation block. 您可以在动画块中对新视图进行任何更改(可能会显示一些新文本,无论......)。

I hope this helps someone out down the line... 我希望这有助于某些人走出困境......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM