我有一个带有选项卡栏的应用程序,每个选项卡中都有导航控制器。当用户摇动设备时,UIImageView
在导航控制器中显示为子视图。但是UIImageView
必须包含特殊图像,具体取决于设备的当前方向。
如果我只写
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)
if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
//Code
}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight||interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
//Code
}
}
如果用户在摇晃之前旋转设备,视图就会变得疯狂。
有没有办法获取iPhone当前的方向?
这里是宏UIDeviceOrientationIsLandscape
and UIDeviceOrientationIsPortrait
所以不用单独检查,你可以这样做......
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
{
// code for landscape orientation
}
OR
if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation))
{
// code for Portrait orientation
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)