UIScrollView 不滚动 [英] UIScrollView not scrolling
本文介绍了UIScrollView 不滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 UIScrollView
,其中包含许多 UIImageView
s、UILabels 等......标签比 UIScrollView
长得多,但是当我运行应用程序时,我无法点击并向下滚动...
I have a UIScrollView
which contains many UIImageView
s, UILabels, etc... the labels are much longer that the UIScrollView
, but when I run the app, I cannot click and scroll down...
为什么会这样?
谢谢
推荐答案
展示完整的工作代码片段总是好的:
It's always good to show a complete working code snippet:
// in viewDidLoad (if using Autolayout check note below):
UIScrollView *myScrollView;
UIView *contentView;
// scrollview won't scroll unless content size explicitly set
[myScrollView addSubview:contentView];//if the contentView is not already inside your scrollview in your xib/StoryBoard doc
myScrollView.contentSize = contentView.frame.size; //sets ScrollView content size
Swift 4.0
let myScrollView
let contentView
// scrollview won't scroll unless content size explicitly set
myScrollView.addSubview(contentView)//if the contentView is not already inside your scrollview in your xib/StoryBoard doc
myScrollView.contentSize = contentView.frame.size //sets ScrollView content size
我还没有找到在 IB 中设置 contentSize 的方法(从 Xcode 5.0 开始).
I have not found a way to set contentSize in IB (as of Xcode 5.0).
注意:如果您使用 Autolayout,最好将此代码放在 -(void)viewDidLayoutSubviews
方法中.
Note:
If you are using Autolayout the best place to put this code is inside the -(void)viewDidLayoutSubviews
method .
这篇关于UIScrollView 不滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文