How to stop displaying a modal view when turning on an iPad?

I use willRotateToInterfaceOrientation to exchange views when my iPad rotates. If I have a modal view or an alert view, when my device rotates and changes view, the view swaps and the alert disappears and does not appear again, even if the alert is again β€œpresented” later.

Edit: I narrowed down this issue a bit. When a modal view is presented by a UIModalPresentationFullScreen , the modal view survives.

What can I do to fix this?

Here is my implementation of willRotateToInterfaceOrientation :

 - (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; // // Load an alternate view depending on the orientation // if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) { [UIView beginAnimations:@"" context:nil]; [self setView:theLandscapeView]; self.view.bounds = CGRectMake(0, 0, 1024, 768); self.view.transform = CGAffineTransformMakeRotation(kDegreesToRadians * (-90)); [UIView commitAnimations]; }else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) { [UIView beginAnimations:@"" context:nil]; [self setView:theLandscapeView]; self.view.bounds = CGRectMake(0, 0, 1024, 768); self.view.transform = CGAffineTransformMakeRotation(kDegreesToRadians * (90)); [UIView commitAnimations]; }else if (toInterfaceOrientation == UIInterfaceOrientationPortrait) { [UIView beginAnimations:@"" context:nil]; [self setView:thePortraitView]; self.view.transform = CGAffineTransformMakeRotation(kDegreesToRadians * (0)); self.view.bounds = CGRectMake(0, 0, 768, 1024); [UIView commitAnimations]; }else if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { [UIView beginAnimations:@"" context:nil]; [self setView:thePortraitView]; self.view.transform = CGAffineTransformMakeRotation(kDegreesToRadians * (180)); self.view.bounds = CGRectMake(0, 0, 768, 1024); [UIView commitAnimations]; } } 
+6
ios objective-c uikit rotation ipad
source share
3 answers

If I were to solve this problem, I would do one of the following

  • Add alternative views to the parent view and do not change the view property
  • Create a design for views that do not require a full swap of views, but reorders or hides sub-elements of the view.
  • Introduce any modal from the root ViewController hierarchy

I would really try not to take my eyes entirely for orientation. It looks like it will continue to present problems even after you solve it.

+2
source share

If you change ideas, you should also change modal ideas, I think.

For example, if you represent a popover controller, it automatically rejects, and then appears with the rotation of the UI.

0
source share

Here's the idea: keep a constant viewpoint, but change the subzone to portrait or landscape view. something like:

 - (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; // Remove the current subview from the main view if (self.view.subviews.count) { [self.view.subviews objectAtIndex:0] removeFromSuperview]; } // Use your if-else block, but change [self setView:] for [self.view addSubview:] } 

So, now when you create your modal, it will be connected to your controller, which now has a constant basic look.

Please note that I have not tested this, since in two weeks I will return back to the encoding ... Good luck!

0
source share

All Articles