mootymoots
mootymoots

Reputation: 4575

Detect 180 flip on iPhone / iPad

I am doing some rejigging of various views from portrait to landscape in my iPhone app. This works fine if the user does Portrait -> Landscape -> Portrait -> Landscape (as I do some math do relocate the views).

However if a user goes from Portait -> Portrait upside down, or Landscape Left -> Landscape Right, my code doesn't work.

Can I detect the 180 flip and ignore it? I tried the following:

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    if ((fromInterfaceOrientation == UIInterfaceOrientationPortrait) && 
        (UIDeviceOrientationIsPortrait(self.interfaceOrientation))
    {
    } 
    else if ((fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) || 
             (fromInterfaceOrientation == UIInterfaceOrientationLandscapeRight) && 
             (UIDeviceOrientationIsLandscape(self.interfaceOrientation)))
    {
    } 
    else 
    {
      // Do something - it didn't flip 180.
    }
}

Upvotes: 2

Views: 677

Answers (1)

Jim Buck
Jim Buck

Reputation: 20726

You need to have parentheses around this part of your logic:

fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || fromInterfaceOrientation == UIInterfaceOrientationLandscapeRight

.. otherwise your logic won't come out as your are expecting. && has higher precedence over ||.

Upvotes: 2

Related Questions