Question

I have a little problem I can't find a way to solve. I have a view inside another view that doesn't rotate when the main view rotates... It's a bit mess up said this way, so I will write a little code:

//in my ViewController:
UIView insideView = [[UIView alloc] initWithFrame:self.view.frame];
insideView.backgroundColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.0];
...
[self.view addSubview:insideView];

Now, I can't realize why, if I roteate my iPhone (simulator), the insideView doesn't follow the main self.view.

Was it helpful?

Solution

Try with following approach

[self.view setAutoresizesSubviews:YES];
[self.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];

The setAutoresizesSubviews property controls whether each view will resize automatically when their bounds change. The setAutoresizingMask property controls how each object resizes automatically.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top