UIScrollView不垂直滚动

Kru*_*nal 4 objective-c uiscrollview ios

我制作了iPhone应用程序,我有这个层次结构,

:当我尝试滚动我的滚动视图时,它不滚动我在我的项目中使用Autolayout

我的scrollview的内容大小比我的scrollview的高度还要大,但它不会滚动.

这是我写的代码片段 viewDidLoad

    UIView *tempo = (UIView *)[scrollVw viewWithTag:6];//View which is inside Scrollview

    float sizeOfContent = 0;
    for (int i = 0; i < [tempo.subviews count]; i++) {
        UIView *view =[tempo.subviews objectAtIndex:i];
        sizeOfContent += view.frame.size.height;

    }

    NSLog(@"sizeOfContent = %f", sizeOfContent);
    scrollVw.contentSize = CGSizeMake(scrollVw.frame.size.width, 1500);

    NSLog(@"scrollVw width = %f -- scrollVw height =%f",scrollVw.frame.size.width, scrollVw.frame.size.height);

    NSLog(@"tempo width = %f -- tempo height =%f",tempo.frame.size.width, tempo.frame.size.height);
Run Code Online (Sandbox Code Playgroud)

记录结果:

sizeOfContent = 1500
scrollVw width = 320.000000      scrollVw height = 416.000000 
tempo width = 320.000000         tempo height =  416.000000
Run Code Online (Sandbox Code Playgroud)

我在哪里做错了?

Mar*_*les 9

如果您使用autolayout,那么您的视图最终会在viewDidLoad之后布局.所以将你的代码移动到viewWillAppear或viewDidLayoutSubviews,你应该没问题.