滚动视图不起作用 IOS 7 [英] Scroll View not functioning IOS 7

查看:21
本文介绍了滚动视图不起作用 IOS 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个滚动视图,里面有 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: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

这篇关于滚动视图不起作用 IOS 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆