問題描述
我在 nib 的 view
中放置了一個 UIScrollView
,并將其鏈接到一個 IBOutlet
屬性.
I put a UIScrollView
in my nib's view
, and linked it to a an IBOutlet
property.
現在,當我在 viewDidLoad
方法中執行此操作時,它似乎對 contentSize
沒有影響:
Now, when I do this in my viewDidLoad
method, it seems to have no effect on the contentSize
:
self.sv.backgroundColor = [UIColor yellowColor]; // this works
CGSize size = CGSizeMake(1000.0, 1000.0);
[self.sv setContentSize:size]; // this does not
它的行為就好像 contentSize
與框架相同.這是怎么回事?當我關閉自動布局時,這開始工作.為什么?
It behaves as if the contentSize
was the same as the frame. What's going on?
This started working when I turned off AutoLayout. Why?
推薦答案
我也遇到了同樣的問題.UIScrollView
的自動布局搞砸了.
I had the same problem. Auto Layout for UIScrollView
is messed up.
解決方法:將 UIScrollView
中的所有內容放入另一個 UIView
,并將該 UIView
作為 UIScrollView 的唯一子項代碼>.然后你可以使用自動布局.
Work around: Put everything in the UIScrollView
into another UIView
, and put that UIView
as the only child of the UIScrollView
. Then you can use Auto Layout.
如果接近尾聲的事情搞砸了(無論您的 UIScrollView
滾動哪個方向的尾端),請將最后的約束更改為盡可能低的優先級.
If things near the end is messed up (the end of whichever direction your UIScrollView
scrolls), change the constraint at the end to have the lowest possible priority.
這篇關于UIScrollView contentSize 不起作用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!