2010年10月22日金曜日

UIScrollViewの初期化と設定

scrollRectToVisibleは下端が優先になる。上部起点で表示したい場合は
画面内に収まるCGRectを指定する。

※hファイルに<uiscrollviewdelegate>追加
- (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;
}