Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A cleaner way is NOT to use UIInterfaceOrientation for the rotation. </p> <p>Why, because then your interface or view 1 actually rotates. This means you have to rotate it back to redisplay it after view 2 is removed. </p> <p>To compensate for this, I simple subscribe to <strong>UIDeviceOrientation</strong> notifications. Subtly different. View 1 does NOT have to support autorotation to make this method work. In viewDidLoad enter the following code:</p> <pre><code>[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectOrientation) name:@"UIDeviceOrientationDidChangeNotification" object:nil]; </code></pre> <p>Then just define the method detectOrientation:</p> <pre><code>-(void) detectOrientation { if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) || ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)) { //load view 2 } else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait) { // load view 1 } } </code></pre> <p>Now neither of your views need support autoratation! You will however need to perform a transform on view 2 before loading:</p> <pre><code>-(void) transformView2ToLandscape { NSInteger rotationDirection; UIDeviceOrientation currentOrientation = [[UIDevice currentDevice] orientation]; if(currentOrientation == UIDeviceOrientationLandscapeLeft){ rotationDirection = 1; }else { rotationDirection = -1; } CGRect myFrame = CGRectMake(0, 0, 480, 300); CGAffineTransform transform = [[self view2] transform]; transform = CGAffineTransformRotate(transform, degreesToRadians(rotationDirection * 90)); [[self view2] setFrame: myFrame]; CGPoint center = CGPointMake(myFrame.size.height/2.0, myFrame.size.width/2.0); [[self view2] setTransform: transform]; [[self view2] setCenter: center]; } </code></pre> <p>Thats how I swap views o rotation without supporting autorotation in my views.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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