Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The problem is that <code>UIDeviceOrientationDidChangeNotification</code> will be fired independently from <code>shouldAutorotateToInterfaceOrientation</code>. And you don't handle the cases <code>UIInterfaceOrientationPortraitUpsideDown</code>, <code>UIDeviceOrientationFaceUp</code> and <code>UIDeviceOrientationFaceDown</code> in the method <code>orientationChanged:</code>. So when the device is rotated to one of these orientations, your code is equivalent to:</p> <pre><code>-(void)orientationChanged:(NSNotification *)object { [UIView commitAnimations]; [self dismissModalViewControllerAnimated:NO]; } </code></pre> <p>So you should remove the lines:</p> <pre><code>[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:)name:@"UIDeviceOrientationDidChangeNotification" object:nil]; </code></pre> <p>and put you code in the method <code>willRotateToInterfaceOrientation</code>:</p> <pre><code>- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration { [UIView beginAnimations:@"View Flip" context:nil]; [UIView setAnimationDuration:0.5f]; [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) { self.view = self.portraitView; } else { self.view = self.landscapeView; } [UIView commitAnimations]; [self dismissModalViewControllerAnimated:NO]; } </code></pre> <p><strong>Edit</strong></p> <p>If you want to keep <code>orientationChanged</code>, then modify it as follows:</p> <pre><code>-(void)orientationChanged:(NSNotification *)object{ UIDeviceOrientation deviceOrientation = [[object object] orientation]; if (deviceOrientation == UIInterfaceOrientationPortrait) { [UIView beginAnimations:@"View Flip" context:nil]; [UIView setAnimationDuration:0.5f]; [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; self.view = self.portraitView; [UIView commitAnimations]; [self dismissModalViewControllerAnimated:NO]; } else if (deviceOrientation == UIInterfaceOrientationLandscapeLeft || deviceOrientation == UIInterfaceOrientationLandscapeRight) { [UIView beginAnimations:@"View Flip" context:nil]; [UIView setAnimationDuration:0.5f]; [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; self.view = self.landscapeView; [UIView commitAnimations]; [self dismissModalViewControllerAnimated:NO]; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload