如何实现UIView的翻转过渡效果

发布于 2024-12-29 00:51:41 字数 94 浏览 5 评论 0原文

如何实现 UIView 的翻转过渡效果,就像“flipboard”应用程序中的那样。这里我已经有可以从左到右或从右到左翻转的示例。但这里我想实现从下到上或从上到下的折叠翻转。

How to implement flip transition effect for UIView as like in "flipboard" application. here i already have sample which will make flip from left to right or right to left. But here i want to implement fold flip from bottom to top or top to bottom.

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

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

发布评论

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

评论(3

山田美奈子 2025-01-05 00:51:41

您可以使用下面的代码行来实现这种动画,

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:5];
[UIView transitionFromView:view2 toView:view1 duration:3 options:UIViewAnimationOptionTransitionFlipFromBottom completion:NULL];
[UIView commitAnimations];  

您可以根据要求设置持续时间和动画过渡..仅在ios5中工作..

you can use the below line of codes for this kind of animations

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:5];
[UIView transitionFromView:view2 toView:view1 duration:3 options:UIViewAnimationOptionTransitionFlipFromBottom completion:NULL];
[UIView commitAnimations];  

u can set the duration and animation transition as per the requirement.. was working only in ios5..

纸伞微斜 2025-01-05 00:51:41

检查本教程: http://www.gethugames.in/blog/2012 /02/extended-epgltransitionview.html
这个项目: https://github.com/saiy2k/EPGLTransitionView

PS:这是我自己的博客和链接到我的 EPGLTransitionView 分支

check this tutorial: http://www.gethugames.in/blog/2012/02/extended-epgltransitionview.html
and this project: https://github.com/saiy2k/EPGLTransitionView

PS: Its my own blog and link to my fork of EPGLTransitionView

南烟 2025-01-05 00:51:41

这是我如何尝试解决该问题的一个概念。也许我会尝试在空闲时间实现它以方便使用示例。

  • 启动动画的那一刻,通过将其图形上下文读入位图来制作当前 UIView 的快照
  • 创建三个(是的,三个 - 请耐心等待) UIView 的大小,以便它们弥补要翻转的视图的两半,右半部分的区域有两个视图
  • 在左视图上绘制位图的一半(第一个),在右视图上绘制右半部分(第二个)一个),在各自的drawRect: 实现
  • 隐藏原始视图
  • 创建我们想要转换的下一个视图,以
  • 将其内容转换为位图,并
  • 隐藏下一个视图
  • 让第三个临时 UIView 绘制图像的右半部分(< em>第三个​​)
  • 第三个​​放置在第二个下方,
  • 第二个沿其左侧翻转的一半进行动画处理边缘
  • 使第二个显示左半边下一个视图
  • 制作其余的翻转动画
  • 完成转换后,显示下一个视图,隐藏所有临时视图
  • Et voilla! 至少我希望如此。

我认为您可以使用一个带有三个 CALayer 的 UIView,而不是这三个 UIView。

并且存在一个以交互方式进行转换的问题,即用户在页面上滑动手指。

我还认为存在双面层的翻转视图问题。还没有机会体验这些属性以及它们可以帮助实现的目标。

另一种解决方案是从 UIView 的内容创建纹理,并在其上放置一个 OpenGL 表面(当然是基于 alpha 透明的 CAEAGLLayer 的表面)。然后,您将如何处理带有该图像纹理的三角形,仅受您的想象力的限制。我想这也将允许创建 Mail iOS 应用程序使用的类似精灵的移动到垃圾箱的动画。

编辑:哦,抱歉,我正在考虑从右到左的翻转板式翻转,而不是从上到下,但总体思路当然是相同的。

Here's a concept of how I would try to approach the problem. Maybe I'll try to implement it in free time to have a sample handy.

  • The moment you start the animation, make a snapshot of current UIView by reading its graphics context into a bitmap
  • Create three (yeah, three -- bear with me_) UIViews with sizes so that they make up for two halves of the view to be flipped, with two views for area of the right half
  • Draw half of the bitmap on the left view (first one), right half on the right view (second one), in their respective drawRect: implementations
  • Hide the original view
  • Create the next view we want to transition to
  • get its contents into a bitmap as well
  • hide the next view
  • make the third temporary UIView to draw the right half of the image (third one)
  • position the third one under the second one
  • Animate half of the flip of the second one along its left edge
  • make the second one display left half of the next view
  • Make the rest of the flip animation
  • After having done the transition, show the next view, hide all temporary views
  • Et voilla! At least I hope.

I think that instead of those three UIViews you could use one UIView with three CALayers instead.

And there's an issue of doing the transition interactively, with the user sliding his finger over the pages.

I also I think there's an issue of the flipping view to have a two-sided layer. Haven't had the opportunity to play with those properties and what they can help to achieve.

Another solution would be to create a texture from UIView's contents and put up an OpenGL surface over it (alpha-transparent CAEAGLLayer-based one of course). Then what you'll do with the triangles that are textured with that image is only limited by your imagination. I guess that would also allow to create a Genie-like move-to-trash animation that Mail iOS app uses.

Edit: Oh, sorry, I was thinking of a right-to-left flipboard-style flip, not top-to-bottom, but overall idea is the same of course.

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