뷰 컨트롤러와 함께 내 뷰의 레이아웃을 제어하기 위해 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 개이므로)? –