0
これで、ユーザーがアプリケーションにログインするときにスクロールビューが読み込まれるようになりました。ユーザーが認証されると、プログラムでスクロールビューを作成する必要があります。これを行うには、私は次のコードを持っています:コンテンツがいっぱいになったらUIScrollViewを拡張する
[scrollView removeFromSuperview];
UIScrollView *view = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, applicationFrame.size.width, self.view.frame.size.height)];
view.backgroundColor = [UIColor greenColor];
//-- get the y-coordinate of the view
CGFloat viewCenterY = self.view.center.y;
//--calculate how much visible space is left
CGFloat freeSpaceHeight = applicationFrame.size.height - keyboardBounds.size.height;
//-- calculate how much the scrollview must scroll
CGFloat scrollAmount = viewCenterY - freeSpaceHeight/2.0;
if(scrollAmount < 0) scrollAmount = 0;
//set the new scrollsize contentview
view.contentSize = CGSizeMake(applicationFrame.size.width, applicationFrame.size.height + keyboardBounds.size.height);
//scroll the scrollview
[view setContentOffset:CGPointMake(0, scrollAmount) animated:YES];
for(int v = 0; v < 15; v++){
CGFloat yCoord = v * 100;
UILabel *mijnLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, yCoord, 200, 50)];
mijnLabel.text = @"1337";
mijnLabel.font = [UIFont fontWithName:@"Verdana" size:20];
mijnLabel.textColor = [UIColor redColor];
[view addSubview:mijnLabel];
[mijnLabel release];
}
[self.view addSubview:view];
[view release];
}
私は追加したラベルの量に応じて私のビューを拡張しますか?また、スクロールビューを画面全体に埋め込む方法を知りたいと思っています。私のスクロールビューは、ポートレートモードでは画面を一杯にするだけです。
これは削除されるログイン画面である:
[scrollView removeFromSuperview];