图像未显示在背景水平滚动视图中的垂直滚动视图上

Image not shown on vertical-scrollView in a background horizontal-scrollView

我想在大背景 UIScrollView 水平显示 3 张长图片(比 iPhone 的屏幕高度长),并且由于每张图片都比屏幕高度长,所以我在背景中放了另外 3 个 Sub-UIScrollView 用于垂直滑动。

我这样设置背景:

_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];
_scrollView.delegate = self;
_scrollView.contentSize = CGSizeMake(screenWidth*_count, screenHeight);
_scrollView.pagingEnabled = YES;
_scrollView.alwaysBounceVertical = NO;
_scrollView.alwaysBounceHorizontal = YES;

我这样设置每个 Sub-UIScrollView

if (imageHeight > screenHeight) { //requiring extra scrollView to support
    UIImageView *longImgView = [[UIImageView alloc] init];
    [longImgView setFrame:CGRectMake(originX, 0, screenWidth, imageHeight)];
    longImgView.image = _image;
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(originX, 0, screenWidth, screenHeight)];
    [scrollView setContentSize:CGSizeMake(screenWidth, imageHeight)];
    [scrollView setContentOffset:CGPointMake(originX, 0)];
    scrollView.backgroundColor = [UIColor blueColor];
    scrollView.alwaysBounceVertical = YES;
    scrollView.alwaysBounceHorizontal = NO;
    [scrollView addSubview:longImgView];
    [_scrollView addSubview:scrollView];
}

请注意我设置scrollView.backgroundColor = [UIColor blueColor];来高亮这个sub-scrollView,但是当我运行它时,我只能看到蓝色的sub-scrollView,我无法看到图片显示(longImgView.image = _image;)。

更新:我可以通过断点和控制台看到分配给 _image 的内存地址。我还可以看到 sub-scrollView 设置了与图像大小相同的 contentSize 但只能看到图像本身。

等待:[longImgView setFrame:CGRectMake(originX, 0, screenWidth, imageHeight)];

做到这一点:

[longImgView setFrame:CGRectMake(0, 0, screenWidth, imageHeight)];