UINavigationController Auto-Rotation to Landscape does not update UIView frame

I am working on an application that works fully in landscape mode (UIStatusBarHidden = YES and UIInterfaceOrientation = UIInterfaceOrientationLandscapeRight). I am using NavigationController with setting rootViewController (MainViewController) as follows:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

In my MainViewController, I load the view as follows:

- (void)loadView {
  CGRect frame = [[UIScreen mainScreen] applicationFrame]; // This returns a portrait frame
  MainView *view = [[MainView alloc] initWithFrame:frame];
  self.view = view;
  [view release];
}

Then in MainView, I load subviews as follows:

- (id)initWithFrame:(CGRect)frame {
  if (self = [super initWithFrame:frame]) {
    self.pdfView = [[PDFView alloc] initWithFrame:frame];
    [self addSubview:pdfView];
  }
   returnself;
}

My problem is that MainView correctly displays in landscape mode (despite the fact that the frame passed to [MainView initWithFrame:] in the portrait), while the child PDFView turns into a portrait frame. I also experimented with transforms in my implementations of [UIView initWithFrame:] as follows:

view.center = CGPointMake(view.frame.size.height/2.0, view.frame.size.width/2.0);
view.transform = CGAffineTransformRotate(view.transform, (M_PI/2.0));

, . , , , :

CGRectMake(0.0, 0.0, 480.0, 320.0)

, .

?

+3
3

, , , . UINavigationController , UITabBarController. , - . UINavigationController UINavigationController, . , , , .

+1

MapView. , :

view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

0

Because MainScreen is always a portrait . see Height and Width on iPhone (/ iPad)

0
source

Source: https://habr.com/ru/post/1706961/


All Articles