简体   繁体   English

UIView 在横向模式下切断

[英]UIView cut off in landscape mode

I have several UIViews added as subViews to my main view controller.我有几个 UIViews 作为子视图添加到我的主视图 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我还尝试将 UIScrollView 添加到主视图,然后将上述子视图添加到滚动视图

- (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.将视图添加到滚动视图后,必须设置滚动视图的contentSize属性,以便滚动视图知道要滚动到的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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