私のアプリケーションでは、CameraAppViewController が 1 つあり、そこから別のビュー コントローラー OverlayViewController に移動し、そこから別のビュー コントローラー ScrollerViewController に移動します。scrollerviewcontroller で uiscrollview を使用したいのですが、スクロールしません。ただし、最初の CameraAppViewController に uiscrollview の同じコードを配置すると、スクロールします。ビューのフレームと比較してスクロールビューのコンテンツサイズを変更するためのすべてのトリックを試しましたが、何も機能しませんでした。1つのView Controllerで動作するので、コードは正しいと思います。私はそれを別のプロジェクトに入れようとしましたが、最初と2番目のView Controllerの両方で機能しました。助けていただければ幸いです。
私が使用するコードは次のとおりです。
UIImage *image1=[UIImage imageNamed:@"logo_idv0.jpg"];
UIImage *image2=[UIImage imageNamed:@"logo_idv1.jpg"];
UIImage *image3=[UIImage imageNamed:@"logo_idv2.jpg"];
NSMutableArray *allImages=[[NSMutableArray alloc] init];
[allImages addObject:image1];
[allImages addObject:image2];
[allImages addObject:image3];
self.view.backgroundColor = [UIColor redColor];
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
scroll.pagingEnabled = YES;
scroll.scrollEnabled = YES;
scroll.clipsToBounds = YES;
NSInteger numberOfViews = 3;
for (int i = 0; i < numberOfViews; i++) {
CGFloat yOrigin = i * self.view.frame.size.width;
UIView *awesomeView = [[UIView alloc] initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];
UIImageView *imageView=[[UIImageView alloc] initWithImage:[allImages objectAtIndex:i]];
[awesomeView addSubview:imageView];
awesomeView.backgroundColor = [UIColor colorWithRed:0.5/i green:0.5 blue:0.5 alpha:1];
[scroll addSubview:awesomeView];
}
scroll.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height+10);
[self.view addSubview:scroll];