我有一个滚动视图,里面有 20 个 UItextview.滚动视图不起作用.我在 viewdidload 中设置了以下内容.
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 的子视图.请指导如何启用滚动!
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 固定到其父视图的两侧,如下所述.
1) Pin UIScrollView to the sides of its parent view, as mentioned below.
2) 在 viewDidLayoutSubviews 中设置滚动视图的内容大小:
2) Set content size of your scroll view in viewDidLayoutSubviews:
- (void)viewDidLayoutSubviews { self.MainScroll.contentSize = CGSizeMake(320, 1800); }方法 2(纯 IB,无需代码):
1) 如果使用AutoLayout,则不需要设置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 作为内容视图并将其固定到 UIScrollView 并移动此内容视图中的所有控件:
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) 将内容视图固定到其父滚动视图,如下所述:
3) Pin content view to its parent scroll view as mentioned below:
4) 将 UIViewController 的模拟指标设置为自由形式(这很重要):
4) Set your UIViewController's Simulated Metrics to Freeform (this is important):
5) 将您的内容 UIView 调整到您想要的高度(显然也很重要):
5) Size your content UIView to your desired height (obviously important too):
Apple 文章解释 UIScrollView 和 AutoLayouts:developer.apple/library/content/technotes/tn2154/_index.html
Apple article explaining UIScrollView and AutoLayouts: developer.apple/library/content/technotes/tn2154/_index.html
更多推荐
滚动视图不起作用 IOS 7
发布评论