問題描述
我有一個滾動視圖,里面有 20 個 UItextview.滾動視圖不起作用.我在 viewdidload 中設(shè)置了以下內(nèi)容.
I have a scrollview inside which i have 20 UItextviews. The scrollview is not working. I have set the following in viewdidload.
self.MainScroll.contentSize = CGSizeMake(320, 1800);
它仍然不滾動.但是,如果我垂直彈跳,它只會彈跳.我的滾動視圖是尺寸為 320*600 的主 UIview 的子視圖.請指導(dǎo)如何啟用滾動!
Still it doesn't scroll. However, if i give bounce vertically, it just bounces. My scrollview is a child of the main UIview of dimension 320*600. Please guide how to enable the scroll!!
推薦答案
有兩種方法可以讓滾動工作.
There are two ways you can get the scrolling to work.
方法一(帶代碼):
1) 將 UIScrollView
固定到其父視圖的兩側(cè),如下所述.
1) Pin UIScrollView
to the sides of its parent view, as mentioned below.
2) 在 viewDidLayoutSubviews
中設(shè)置滾動視圖的內(nèi)容大小:
2) Set content size of your scroll view in viewDidLayoutSubviews
:
- (void)viewDidLayoutSubviews {
self.MainScroll.contentSize = CGSizeMake(320, 1800);
}
方法 2(純 IB,無需代碼):
1) 如果使用AutoLayout
,則不需要設(shè)置contentSize
.您需要將 UIScrollView
固定到父視圖,如下所述:
1) Setting contentSize
is not required if using AutoLayout
. You need to pin your UIScrollView
to the parent view as mentioned below:
2) 然后在 UIScrollView 中添加另一個 UIView
作為內(nèi)容視圖并將其固定到 UIScrollView 并移動此內(nèi)容視圖中的所有控件:
2) Then add another UIView
inside UIScrollView to act as a content view and pin it to the UIScrollView and move all controls inside this content view:
3) 將內(nèi)容視圖固定到其父滾動視圖,如下所述:
3) Pin content view to its parent scroll view as mentioned below:
4) 將 UIViewController 的模擬指標(biāo)設(shè)置為自由形式(這很重要):
4) Set your UIViewController's Simulated Metrics to Freeform (this is important):
5) 將您的內(nèi)容 UIView
調(diào)整到您想要的高度(顯然也很重要):
5) Size your content UIView
to your desired height (obviously important too):
Apple 文章解釋 UIScrollView 和 AutoLayouts:https://developer.apple.com/library/content/technotes/tn2154/_index.html
Apple article explaining UIScrollView and AutoLayouts: https://developer.apple.com/library/content/technotes/tn2154/_index.html
這篇關(guān)于滾動視圖不起作用 IOS 7的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!