Auto-resist mask and full screen mode

I am experimenting with something weird. I want to create a view that will fit all my screens (minus statusBar minus navBar). Here's what I did in mine 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];

      

If I leave the autoresist line commented out it works great, but when I rotate it no longer fits (which is expected).

If I uncomment the autoresist line when I first run in portrait mode, the size of my view is something like 320x430 and when I first run in landscape mode it's like 480x200 ... With "first run" I mean " from another view "".

I tried adding flexible fields, but it didn't fix it (I want it fullscreen anyway, so (x, y) will always be (0,0).

+3


source to share


1 answer


The UINavigationController will resize its child views, so you don't have to consider navigation or status bar. You just need to add this view to the VC view and set it to flexible width / height so that it will fill the parent view.



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

      

+6


source







All Articles