【问题标题】:Autoresizing mask and full-screen view自动调整蒙版和全屏视图
【发布时间】:2013-02-19 07:48:37
【问题描述】:

我正在尝试一些奇怪的东西。我想创建一个适合我所有屏幕的视图(减去状态栏减去导航栏)。这是我在viewDidLoad 中所做的:

CGFloat navHeight = self.navigationController.navigationBar.frame.size.height;
UIView *test = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight-20-navHeight)];
test.backgroundColor = [UIColor greenColor];
//test.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:test];

如果我留下 autoresizing 行的注释,这可以正常工作,但是当我旋转时,它不再适合(这是预期的)。

如果我取消注释自动调整大小行,当我第一次以纵向模式启动时,我的视图大小类似于 320x430,而当我第一次以横向模式启动时,它就像 480x200... 对于“首次启动”,我的意思是“来自另一个视图”。

我尝试添加灵活边距,但没有解决(无论如何我希望它是全屏的,所以 (x,y) 将始终为 (0,0)。

【问题讨论】:

    标签: ios autoresizingmask


    【解决方案1】:

    UINavigationController 将为您调整其子视图的大小,因此您不必考虑导航或状态栏。您只需要将此视图添加到 VC 的视图中并将其设置为灵活的宽度/高度,以便填充父视图。

        UIView *test = [[UIView alloc] initWithFrame:self.view.bounds];
        test.backgroundColor = [UIColor greenColor];
        test.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        [self.view addSubview:test];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-08
      相关资源
      最近更新 更多