在 iPhone / iPad 上检测 180 度翻转
我正在 iPhone 应用程序中对各种视图(从纵向到横向)进行一些重新调整。如果用户执行 Portrait -> 则效果很好。风景->肖像 ->景观(当我做一些数学计算时,会重新定位视图)。
然而,如果用户从Portait ->纵向颠倒,或横向左 ->景观 好吧,我的代码不起作用。
我可以检测到 180 度翻转并忽略它吗?我尝试了以下方法:
-(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.
}
}
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.
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在逻辑的这一部分周围加上括号:
..否则您的逻辑将不会按照您的预期出现。
&&
的优先级高于||
。You need to have parentheses around this part of your logic:
.. otherwise your logic won't come out as your are expecting.
&&
has higher precedence over||
.