ダブルタップでズームインしUIImageView
ています。UIScrollView
Interface Builder でセットアップすると正常に動作します。ここで見られる魔法は、contentSize
ズームインscrollView
/ズームアウトするにつれて自然に増加/減少することです。contentSize
inをチェックしますがviewDidLoad
、ゼロではありません。
scrollView
IB からandを削除して同じことを試み、imageView
プログラムで作成しました。imageView
とを追加した後、tapGestureRecognizer
ここでズームに失敗しました。理由を調べてみると、contentSize
どこもゼロのまま。
それらを IB/xib に追加すると、contentSize
. 私はどこにも設定していません。必要な場所で自動的にcontentSize
調整されます。しかし、scrollView
プログラムで作成すると複製されません。
どうすればそれを機能させることができますか? あなたの提案を歓迎します。
参照用の私のコードは次のとおりです。
IB で作成された ScrollView
- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
[doubleTap setNumberOfTapsRequired:2];
[imageView addGestureRecognizer:doubleTap];
imageScrollView.minimumZoomScale=1.01;
imageScrollView.maximumZoomScale=5;
imageScrollView.zoomScale=1.01;
NSLog(@"height = %f width = %f", imageScrollView.contentSize.height, imageScrollView.contentSize.width);
}
NSLogは言う
height = 449.479767 width = 320.000000
プログラムで作成された ScrollView
- (void)viewDidLoad {
[super viewDidLoad];
imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
[doubleTap setNumberOfTapsRequired:2];
[imageView addGestureRecognizer:doubleTap];
imageScrollView.minimumZoomScale=1.01;
imageScrollView.maximumZoomScale=5;
imageScrollView.zoomScale=1.01;
[self.view addSubview:imageScrollView];
[self.imageScrollView addSubview:imageView];
NSLog(@"height = %f width = %f", imageScrollView.contentSize.height, imageScrollView.contentSize.width);
}
NSLogは言う
height = 0.000000 width = 0.000000