UIScrollView不滚动 [英] UIScrollView not scrolling

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

问题描述

我有一个 UIScrollView ,其中包含许多 UIImageView s,UILabels等...标签更长那个 UIScrollView ,但是当我运行应用程序时,我无法点击并向下滚动...

I have a UIScrollView which contains many UIImageViews, 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 方法。

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

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