3
votes

I have UIViewController without a xib, and I'm using loadView to build my UI that creates and adds two scroll views. The thing is, the main view frame size is not changing when rotation happens. I mean, I'm setting initial frame size for the main view in loadView (portrait mode: frame size width = 320, height = 480). After rotation to landscape orientation, the view main frame size isn't changing and is the same as in portrait mode. Here's my loadView:

-(void)loadView{

  CGRect screenBounds = [[UIScreen mainScreen] bounds];    
  self.view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, screenBounds.size.width, screenBounds.size.height)] autorelease];
  self.view.autoresizingMask = (UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
  self.scrollView1 = [[[UIScrollView alloc] init] autorelease];
  self.scrollView1.frame = CGRectMake...
  [self.view addSubview:self.scrollView1];
  self.scrollView2 = [[[UIScrollView alloc] init] autorelease];
  self.scrollView2.frame = CGRectMake...
  [self.view addSubview:self.scrollView2];

I have also set autoresizingMask for the view to expand or shrink to fit the screen. But I'm getting the same width and height values when debugging that in console. I need to get a new size because I need to reposition my two scrollViews when rotation happens, for example to shrink the height and expand the width on the scrollViews on rotation to landscape mode. I could do manually in shouldRotate, just curious about how it should be done in proper way.

1

1 Answers

9
votes

I have noticed that self.view.frame size does not change but self.view.bounds does on rotation, and bounds represent correct values with respect to current interface orientation.