首先,这个问题的奇怪之处在于我在 iPhone 上没有遇到同样的问题,它只是发生在 iPad 上。下面的代码只采用字符串数组,这些字符串是应用程序包中图像的路径,并将这些图像作为 imageView 放到我的自定义 UIScrollView 中。它的工作只是为页面显示图片。当用户翻页时,它会在滚动视图的范围内显示下一张照片。所以这个想法基本上是分页。它在滚动视图的范围内非常适合 iPhone。但是,在 iPad 中,它实际上在其范围内也能正常工作,但问题是页面的其他图像也会显示在屏幕上,即使 scrollView 的边界和 contentOffSet 值不应该显示它们,页面会占用所有屏幕即使我的 masterViewController 也在屏幕上,我也翻了页,因此 scrollView 的图像超越了屏幕上的所有内容并使其可见。实际上,scrollView 的图像不起作用,因为它们无法识别手势事件,而是 scrollView 当前在其边界中显示的事件。那么可能是什么问题呢?我用谷歌搜索了它,但我认为没有人遇到过类似的问题。我为 scrollView 创建 imageViews 的代码如下,但正如我所说,它可以在 iPhone 中工作,不会溢出其他图像。谢谢你。我为 scrollView 创建 imageViews 的代码如下,但正如我所说,它可以在 iPhone 中工作,不会溢出其他图像。谢谢你。我为 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;
}
当方向从纵向旋转到横向时,会出现此问题。如果应用程序以横向方向启动,scrollView 按我的意愿工作,但是当我首先将其旋转到纵向,然后再将其旋转到横向时,我正在谈论的问题就会发生,正如您在屏幕截图中看到的那样。
最初横向-没问题,再次翻页时没问题。关闭的页面不会显示在任何其他视图的任何位置
当设备从纵向旋转到横向并且图片向屏幕左侧滚动时,masterViewController 的视图甚至在 detailViewController 上都变得很奇怪。怎么会发生?