拡大率をかえたくない場合は以下。
// 現在のスケール float scale = scrollV.zoomScale; // ズームスクロール CGRect rect = CGRectMake(0,0,10,10); [scrollV zoomToRect:rect animated:YES]; // スケールを再指定 [scrollV setZoomScale:scale];
*参考記事*
UIScrollViewで任意の位置にスクロール
// 現在のスケール float scale = scrollV.zoomScale; // ズームスクロール CGRect rect = CGRectMake(0,0,10,10); [scrollV zoomToRect:rect animated:YES]; // スケールを再指定 [scrollV setZoomScale:scale];
- (void)viewDidLoad {
[super viewDidLoad];
UIView*contentView=[[UIView alloc]initWithFrame:CGRectMake(0,0,1000,1000)];
UIScrollView*Scroll=[[UIScrollView alloc]initWithFrame:[self.view frame]];
[Scroll addSubview:contentView];
[self.view addSubview:Scroll];
Scroll.contentSize=contentView.frame.size;
Scroll.delegate = self;
CGRect motorect=[self.view frame];
CGRect contentrect=[contentView frame];
//コンテント横が全体に収まるような拡大率を100%(最小表示)とする
//最小表示から5倍まで拡大できる
Scroll.minimumZoomScale = motorect.size.width/contentrect.size.width;
Scroll.maximumZoomScale = modeAScroll.minimumZoomScale*5;
//全体表示する(画面より縦長だと左上表示) YESでアニメーションあり
[Scroll setZoomScale:Scroll.minimumZoomScale animated:NO];
[Scroll scrollRectToVisible:CGRectMake(0,0,1,1) animated:NO];
}
//ズームする場合は必要
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return contentView;
}