Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to intercept iPhone rotation
    text
    copied!<p>in my app I got a Home with several buttons. Each button opens a separate view. In each view, if I put the device in landscape a help view is shown. Everything works fine except that in whatever view I am, if I put the iPhone like to lay on a table (I don't know how to eplain better...) the app exites from that view and comes back to the first view, the Home. Here's my code: </p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:)name:@"UIDeviceOrientationDidChangeNotification" object:nil]; [self performSelector:@selector (ritardo) withObject:nil afterDelay:5.0f]; } -(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; } 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]; } -(void) ritardo { ruota.image = [UIImage imageNamed:@"RuotaPerAiuto.png"]; } - (void)viewDidUnload { [self setPortraitView:nil]; [self setLandscapeView:nil]; [self setRuota:nil]; [super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } else { return YES; } } @end </code></pre> <p>Hi hope you can help me</p> <p>EDIT: I modified the -(void)orientationChanged:(NSNotification *)object{ in this way:</p> <pre><code>-(void)orientationChanged:(NSNotification *)object{ UIDeviceOrientation deviceOrientation = [[object object] orientation]; if (deviceOrientation == UIDeviceOrientationFaceUp)// || deviceOrientation == UIDeviceOrientationFaceDown) { return; } if (deviceOrientation == UIInterfaceOrientationPortrait || deviceOrientation == UIInterfaceOrientationPortraitUpsideDown) { [UIView beginAnimations:@"View Flip" context:nil]; [UIView setAnimationDuration:0.5f]; [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; self.view = self.portraitView; } 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> <p>Now, if I'm in portrait and get the iPhone to faceUp position works good. But when I change position from faceUp to portrait it goes back to the home...</p>
 

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