UIScrollView サンプル
コーディング時に大枠を何処かからコピーペーストして修正実装
するパターンがよくあると思います。
実装時、コピペ用のテンプレートとしてご利用ください。
コードサンプル
■ 基本 UIScrollView *testScrollView = [[UIScrollView alloc] init]; testScrollView = [[UIScrollView alloc] init]; testScrollView.delegate = self; testScrollView.frame = self.view.bounds; testScrollView.contentSize = CGSizeMake(320, 1000); testScrollView.backgroundColor = [UIColor whiteColor]; testScrollView.scrollEnabled = YES; [self.view addSubview:testScrollView]; ■ 写真拡大用 UIImageView *imageView = [[UIImageView alloc] init]; UIScrollView *testScrollView = [[UIScrollView alloc] init]; testScrollView.frame = self.view.bounds; testScrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; testScrollView.contentSize = imageView.bounds.size; testScrollView.backgroundColor = [UIColor blackColor]; testScrollView.minimumZoomScale = 1.0; testScrollView.maximumZoomScale = 3.0; testScrollView.delegate = self; [testScrollView addSubview:testScrollView]; ■ 他、必要に応じて testScrollView.showsVerticalScrollIndicator = NO; testScrollView.showsHorizontalScrollIndicator = NO; testScrollView.scrollsToTop = NO; testScrollView.bounces = NO; ■ UIScrollViewDelegate #pragma mark UIScrollViewDelegate Methods - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ NSLog(@"- (void)scrollViewDidScroll:(UIScrollView *)scrollView"); } - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{ NSLog(@"- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate"); } - (UIView*)viewForZoomingInScrollView:(UIScrollView*)scrollView { for ( id subview in scrollView.subviews ) { if ( [subview isKindOfClass:[UIImageView class]] ) { return subview; } } return nil; }