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)fr开发者_运维技巧omInterfaceOrientation {
if ((fromInterfaceOrientation == UIInterfaceOrientationPortrait) &&
(UIDeviceOrientationIsPortrait(self.interfaceOrientation))
{
}
else if ((fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
(fromInterfaceOrientation == UIInterfaceOrientationLandscapeRight) &&
(UIDeviceOrientationIsLandscape(self.interfaceOrientation)))
{
}
else
{
// Do something - it didn't flip 180.
}
}
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 ||
.
精彩评论