ios滚动视图难题 [英] ios scrollview cunundrum

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

问题描述

我有一个滚动视图,它成功地填充了视图,但它没有滚动,有人能明白为什么吗?

I have a scroll view which is populating with views successfully however it isnt scrolling, can anyone see why?

   CGRect fullScreenRect=[[UIScreen mainScreen] applicationFrame];

    UIScrollView *scrollView=[[UIScrollView alloc] initWithFrame:fullScreenRect];

    [scrollView setContentSize:self.view.frame.size];

    if (sqlite3_open(dbpath, &xxx) == SQLITE_OK)
    {
// code that works        
        if (sqlite3_prepare_v2(xxx, query_stmt, -1, &statement, NULL) == SQLITE_OK)
        {
            while (sqlite3_step(statement) == SQLITE_ROW)
            {
//more code that works                
                //add image view to view
                [scrollView addSubview:myImageView];

                i = i + 1;
            } 
            sqlite3_finalize(statement);
        }
        sqlite3_close(xxx);
    }

    self.view=scrollView;

推荐答案

为了使 scrollview 可滚动,您需要将其 contentSize 属性设置为能够包含所有内容(因此很可能大于 scrollview 框架).例如,如果您想水平滚动视图,则需要将 contentSize 宽度设置为图像视图数的倍数:

In order to make scrollview scrollable you need to set its contentSize property to be able to contain all your contents (and so most likely larger than scrollview frame). For example in case you want to scroll your views horizontally you'll need to set contentSize width to a multiple of the number of your image views:

...
// Loaded data and created subviews
// Now set contentSize
[scrollView setContentSize:CGSizeMake(imageWidth*numberOfImages, self.view.frame.size.height)];

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

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