我有一个分页 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.
我的视图旋转正常,并设法正确设置 contentSize、边界和子视图的框架以适应不同的方向.所以旋转前后,一切正常.
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"!
这篇关于清除分页 UIScrollView 中的自动旋转转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!