ios scrollview cunundrum

2019-08-30 18:58发布

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;

1条回答
三岁会撩人
2楼-- · 2019-08-30 19:07

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)];
查看更多
登录 后发表回答