在分页UIScrollView中清除自转过渡 [英] Clean autorotation transitions in a paging UIScrollView

查看:165
本文介绍了在分页UIScrollView中清除自转过渡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个分页UIScrollView,其中用户水平浏览图像,如Apple的Photos.app。这有效,但现在我正在尝试添加旋转支持。

I have a paging UIScrollView in which the user pages horizontally through images, like Apple's Photos.app. That works, but now I'm trying to add rotation support.

我已经让视图旋转OK并设法设置contentSize,bounds和subviews'适当地框架以适应不同的方向。所以在旋转之前和之后,一切都很好。

I've got the view rotating OK and have managed to set the contentSize, bounds, and subviews' frames properly to adapt to the different orientations. So before and after the rotation, everything is OK.

然而,过渡本身很尴尬。第一个图像完美旋转,就像旋转轴位于图像的死点(滚动视图框)一样。第二个图像摆动,因为旋转轴位于相同的位置:第一个图像的中心。我从第一张图片越远,摇摆越快。

However, the transitions themselves are awkward. The first image rotates perfectly, as if the axis of rotation is in the dead center of the image (scrollview frame). The second image "swings" in because the axis of rotation is in the same place: the center of the first image. The farther away I get from the first image, the faster the "swing."

我可以通过在旋转之前覆盖不透明的UIView并在之后隐藏它来掩盖它。但这是一个黑客。必须有一种优雅的方式来做到这一点...

I can probably mask this by overlaying an opaque UIView before rotation and hiding it after. But that's a hack. There must be an elegant way to do this...

推荐答案

坦率地说,我不知道你在做什么,因为你没有向我们展示太多。

Frankly, I don't know what you're doing, since you haven't shown us much at all.

但是!

我创建了一个示例项目滚动视图中的几个视图,它工作正常。您可以根据需要随意挑选它。它的工作原理是创建5个视图,并将它们添加到滚动视图中。然后在第一次设置这些视图后,每次应用程序旋转时,它都会调用我的方法 alignSubviews 将它们放在正确的页面位置并使它们成为与滚动视图相同的大小,同时更新滚动视图的 contentSize 。在旋转发生之前,它会跟踪滚动视图当前所在的页面,然后在旋转期间将其重置为该页面(因为页面大小必须更改)。

I created a sample project with a few views in a scroll view, and it works fine. Feel free to pick it apart as you wish. It works by creating 5 views, and adding them to the scroll view. Then after these views are set up for the first time, and every time the application rotates, it calls my method alignSubviews to lay them out at the right page locations and make them the same size as the scroll view, while updating the scroll view's contentSize. Before the rotation occurs, it keeps track of what page the scroll view is currently on, and then resets it to that page during the rotation (because the page size has to change).

下载Rotolling!

截图http://cl.ly/43de79be29c5a03a1775/content

这篇关于在分页UIScrollView中清除自转过渡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆