問題描述
我有一個分頁 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 中的自動旋轉轉換的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!