UIScrollView 显示其所有内容,即使 contentOffSet 和bounds 在 Objective-C 中没有覆盖它们

问题描述 投票:0回答:1

首先,问题的奇怪之处在于我在iPhone中没有遇到同样的问题,它只是发生在iPad上。下面的代码仅采用字符串数组(它们是应用程序包中图像的路径),并将这些图像作为 imageView 放入我的自定义 UIScrollView 中。它的工作只是显示页面的图片。当用户翻页时,它会在滚动视图的边界中显示下一张照片。所以这个想法基本上就是分页。它在iPhone 的scrollView 边界下工作得很好。然而,在iPad中,它实际上在其边界内工作得很好,但问题是页面的其他图像也会显示在屏幕中,即使scrollView的边界和contentOffSet值不应该显示它们,页面也会离开所有屏幕,因为即使我的 masterViewController 也在屏幕上,我也翻页了,因此,scrollView 的图像超出了屏幕上的所有内容,并使自身可见。实际上,scrollView 的图像不起作用,因为它们无法识别手势事件,但滚动视图当前在其边界中显示的图像。那么可能是什么问题呢?我用谷歌搜索了一下,但我认为没有人遇到过类似的问题。我为scrollView创建imageViews的代码如下,但正如我所说,它在iPhone中工作不会溢出其他图像。谢谢你。

- (void)loadImagesAtPaths:(NSArray *)paths inFrame:(CGRect)frame
{
    CGFloat newWidth = CGRectGetWidth(frame)*paths.count; //width for contentSize with respect to number of images so that it covers all images in its contentSize

    for( UIView *view in self.subviews) [view removeFromSuperview]; //removing old imageViews

    self.contentSize = CGSizeMake(newWidth, CGRectGetHeight(frame));

    for( NSUInteger currentImageIndex = 0; currentImageIndex < paths.count; currentImageIndex++){

        UIImage *imageForImageView = [UIImage imageNamed:[paths objectAtIndex:currentImageIndex]];

        CGRect frameForImageView = CGRectMake(CGRectGetWidth(frame)*currentImageIndex, 0, CGRectGetWidth(frame), CGRectGetHeight(frame)); //paging the imageView

        UIImageView *currentImageView = [[UIImageView alloc] initWithFrame:frameForImageView];
        currentImageView.contentMode = UIViewContentModeScaleToFill;
        currentImageView.image = imageForImageView;

        [self addSubview:currentImageView];
    }

    self.pagingEnabled                  = YES;
    self.userInteractionEnabled         = YES;
    self.showsHorizontalScrollIndicator = NO;
    self.showsVerticalScrollIndicator   = NO;
    self.scrollsToTop                   = NO;
}

当方向从纵向旋转到横向时,会出现此问题。如果应用程序以横向启动,则滚动视图可以按我的意愿工作,但是当我首先将其旋转到纵向,然后再次旋转到横向时,就会出现我正在谈论的问题,正如您在屏幕截图中看到的那样。

最初横向没有问题,再次翻页时没有问题。关闭的页面不会在任何其他视图的任何位置显示 IMAGE App launched in landscape orientation initially - No scrolling IMAGE During scrolling, again no problem since app launched in landscape orientation

当设备从纵向旋转到横向并且图片向屏幕左侧滚动时,一切都变得很奇怪,masterViewController 的视图甚至出现在DetailViewController 上。怎么会发生呢? IMAGE View is scrolled left

ios objective-c ipad pagination uiscrollview
1个回答
1
投票

如果我理解正确的话,你说其他图像与你当前的图像重叠。如果发生这种情况,你可以将滚动的图像移到顶部

[self bringSubviewToFront:imageview]
,然后如果这适合屏幕,那么它将是唯一可见的。

如果您还有其他意思,请说得更详细。

© www.soinside.com 2019 - 2024. All rights reserved.