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

发布于 2025-01-08 01:20:57 字数 987 浏览 1 评论 0原文

我目前正在通过执行以下操作来执行卷曲动画:

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];

该动画将仅执行页面卷曲动画,但最终您将看到与开始时相同的视图。从未发生过真正的转变。

现在使用动画块,我知道您可以执行以下操作:

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

但是,使用动画块您将转换到新视图 aNewView,它与上面的 CATransition 动画不同,后者重用相同的视图(没有发生真正的转变)。动画块的问题是,您必须实际创建要转换到的新视图,这在我的情况下很麻烦,因为视图相当复杂,而且我不想创建 UIView 子类。

有没有办法使用动画块执行上述 CATransition 动画,同时解决必须重建视图或创建自定义子类的困难?

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). 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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

も让我眼熟你 2025-01-15 01:20:57

好的 - 所以我为任何感兴趣的人找到了答案。其实非常简单。您可以简单地使用以下方法: transitionWithView:duration:options:animations:completion:

例如:

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

就是这样。这将显示返回同一视图的过渡动画。您可以在动画块中对新视图进行任何所需的更改(可能显示一些新文本,无论如何......)。

我希望这可以帮助某人走出困境......

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:

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文