Pregunta

I have an app that implements the UISplitViewController. Both detail and master VCs are embedded in navigation controllers. However, when the detail navigator controller is showing its root/top level view, I'd like the master view was hidden.

On iOS 6 I can accomplish this with:

- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];
  [[self splitViewController] setDelegate:nil];
  [[self splitViewController] setDelegate:self];
  [[[self splitViewController] view] setNeedsLayout];
  [[self splitViewController] willRotateToInterfaceOrientation:CURRENT_ORIENTATION duration:0];
  [[self view] setNeedsLayout];
}

However the same code does not work on iOS 7.
After the transition, the master view does actually hide, but the detail does not fit the whole screen, and there is a gray spacing on the right side which is the same width as the master's. If the device is rotated twice, then it will fill the screen.

On iOS 6, after the view transition, the detail will automatically fill the screen.

¿Fue útil?

Solución

Got it! I replaced the code above with the code below. Now it works on both iOS 6 and 7.

- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];
  [[self splitViewController] setDelegate:nil];
  [[self splitViewController] setDelegate:self];
  [[self splitViewController] willAnimateRotationToInterfaceOrientation:CURRENT_ORIENTATION duration:0];
  [[self splitViewController] willRotateToInterfaceOrientation:CURRENT_ORIENTATION duration:0];
  [[self splitViewController] didRotateFromInterfaceOrientation:CURRENT_ORIENTATION];
  [[self splitViewController] viewWillLayoutSubviews];
  [[[self splitViewController] view] layoutSubviews];
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top