私はUIViewを使ってビューのレイアウトをコントロールしています(ビューコントローラと一緒に)。私は、UIScrollViewが垂直画面の半分しか使用しないようにします。画面の上半分を使用するとうまく動作しますが、下半分は使用できません。UIScrollViewを含むUIViewのレイアウトを尊重する方法は?
ここでのUIViewControllerから該当するコードです:
- (void)loadView {
CGRect fullFrame = [[UIScreen mainScreen] applicationFrame];
//trying to put the scroll view on the bottom half of the screen, but does not work.
CGRect halfFrame = CGRectMake(0, fullFrame.size.height/2 ,
fullFrame.size.width, fullFrame.size.height/2);
//use this instead for the scroll view to go to the top half of the screen (and work properly)
//CGRect halfFrame = CGRectMake(0, 0 , fullFrame.size.width, fullFrame.size.height/2);
UIScrollView* sv = [[UIScrollView alloc] initWithFrame:halfFrame];
[sv setContentSize:CGSizeMake(3 * halfFrame.size.width, halfFrame.size.height)];
CGRect stencilFrame = halfFrame;
UIView *leftView = [[UIView alloc] initWithFrame:stencilFrame];
stencilFrame.origin.x += stencilFrame.size.width;
UIView *centerView = [[UIView alloc] initWithFrame:stencilFrame];
stencilFrame.origin.x += stencilFrame.size.width;
UIView *rightView = [[UIView alloc] initWithFrame:stencilFrame];
//mix up the colors
[leftView setBackgroundColor:[UIColor redColor]];
[centerView setBackgroundColor:[UIColor greenColor]];
[rightView setBackgroundColor:[UIColor blueColor]];
//add them to the scroll view
[sv addSubview:leftView];
[sv addSubview:centerView];
[sv addSubview:rightView];
//turn on paging
[sv setPagingEnabled:YES];
UIView *containerView = [[UIView alloc]initWithFrame:fullFrame];
[containerView addSubview:sv];
[self setView:containerView];
}
は、任意のアドバイスや助けを事前にありがとうございます。
確かに、私は私がフォローしているかどうかはわかりません。 "3つのビューがあるので、"個々のビューの3 *フレーム幅に等しい "内のスクロール可能なコントロールの合計サイズ"ですか? –