Reputation: 609
I have rotation problem on UISplitViewController
. In my case, after calling present modal on splitViewController
(this splitViewController is the root view of window) to show another view. When that modalView is rotated, the splitView rotate incorrectly.
The splitView appears like it rotated, but the DetailViewController
stays like it appear on portrait, and the RootViewController
did not show at all. It still behave like on portrait mode. It seems that the splitView is rotated, but not the underlying views (DetailViewController
and RootViewController
).
I try to implement willRotateToInterfaceOrientation
on the modalView, and call the splitView's willRotateToInterfaceOrientation
method using delegate.
This is what I implement in modalView:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
MacProjectAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.splitViewController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
The result is, the DetailViewController
behave correctly, but not with RootViewController
. It stay hidden. It will re-appear after the user manually rotate to portrait and back to landscape. But obviously user did not want that.
This is what I did when presenting modalView:
ModalViewController *modalView = [[ModalViewController alloc] init];
MacProjectAppDelegate *delegate = (MacProjectAppDelegate *)[[UIApplication sharedApplication] delegate];
[delegate.splitViewController presentModalViewController:modalView animated:YES];
[modalView release];
Is there a way to show the RootViewController
in this case? Or is my doing things is wrong?
Edit:
It seems all views did not rotate following the modalView. neither the RootViewController nor DetailViewController did rotate (the didRotateFromOrientation
on both ViewController did not called at all). So now I assume it didn't rotate following the device/modalView.
Upvotes: 1
Views: 1895
Reputation: 609
OK. My problem has been solved. What I did is as I wrote as comment on Shurakov's comment.
I acquire appDelegate and get the splitViewController to call willRotateToInterfaceOrientation.
MacProjectAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.splitViewController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
I did it twice since only one of them seems did not work (I don't know why). One at modalViewController
's willRotateToInterfaceOrientation
method, one at RootViewController
's willAppear
method.
To remove the navigator/popover button on DetailViewController
, I simply invalidate that button by calling invalidateRootPopoverButtonItem
at RootViewController
's willAppear
method. This is what it's looks like on this particular method (for the first one at modalViewController
, I just pass the willRotateToOrientation
command to splitViewController
):
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (UIInterfaceOrientationIsLandscape(orientation)) {
MacProjectAppDelegate *delegate = (MacProjectAppDelegate *)[[UIApplication sharedApplication] delegate];
[delegate.splitViewController willRotateToInterfaceOrientation:orientation duration:1];
[[[delegate.splitViewController viewControllers] objectAtIndex:1] invalidateRootPopoverButtonItem:self.rootPopoverButtonItem];
}
Hope this can explain how I overcome my problem and help anyone who had the same problem as me.
Upvotes: 1