开发者

UIScrollView not scrolling

开发者_Python百科

I'm loading a UIScrollView with UIImageViews. imageViews below is an NSMutableDictionary of UIImageViews. The scrollview is an IBOutlet with scrolling and paging enabled. The loop adds two images. However, I only ever see the first image in the scrollview and am not able to scroll. Is there something else I need to enable for scrolling to work?

for(NSString *s in [imageViews allKeys]){
    UIImageView *myImageView = [imageViews valueForKey:s];
    myImageView.frame = CGRectMake(0, 0, 120, 90);
    myImageView.contentMode = UIViewContentModeScaleAspectFit;
    scrollView.contentSize = CGSizeMake(120, 90);
    [scrollView addSubview:myImageView];
}

[scrollView layoutSubviews];


I'm guessing your scrollView in IB is about 120x90? Then you'll need to set your contentSize to be at least 240x90 in case of 2 images, and (n * 120)x90 for n the amount of imageViews, assuming you want to be able to scroll/page horizontally. This is because the contentSize indicates the entire "virtual" area of your images.

Also: you're currently placing each imageView at the same coordinates:

myImageView.frame = CGRectMake(0, 0, 120, 90)

This is why you only see one image, they overlap. You'll need to place each consecutive imageView at least 120 to the right of the previous.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜