简体   繁体   中英

UIView cut off in landscape mode

I have several UIViews added as subViews to my main view controller. The way I have the views laid out looks fine in portrait mode, however, when it is tilted in to landscape mode, the bottom parts of the subviews gets cut off. I figured if I set the height of the frame, it would allow the screen to scroll and thus reveal the parts of the subViews that were cut off - but it doesn't.

- (void)didRotate:(NSNotification *)notification {

    UIDeviceOrientation orientation = [[notification object] orientation];

    if (orientation == UIDeviceOrientationLandscapeLeft) {
        self.view.frame = CGRectMake(0.0, 0.0, 1024.0, maxHeight);
    } else if (orientation == UIDeviceOrientationLandscapeRight) {
        self.view.frame = CGRectMake(0.0, 0.0, 1024.0, maxHeight);
    }
}

I also tried adding a UIScrollView to the main view, then adding the afore mentioned subViews to the scrollView

- (void)viewDidLoad
{
    scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
    [self.view addSubview:scrollView];

    //add views to scrollView

    [super viewDidLoad];
}

How can I make the main view "scroll" if the sub-views exceed the screen size?

After you add your views to the scroll view, you must set the contentSize property of the scroll view so that the scroll view knows there's content to be scrolled to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM