滚动视图不起作用 IOS 7

编程入门 行业动态 更新时间:2024-10-28 06:29:56
本文介绍了滚动视图不起作用 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:developer.apple/library/content/technotes/tn2154/_index.html

Apple article explaining UIScrollView and AutoLayouts: developer.apple/library/content/technotes/tn2154/_index.html

更多推荐

滚动视图不起作用 IOS 7

本文发布于:2023-11-03 01:04:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1553863.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   不起作用   IOS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!