您可以检查设备的方向,然后设置一个标志,确定您处于左侧还是右侧。然后,当您的设备切换时,您可以抓住它并根据需要进行处理。
要确定方向使用:
if([UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft)
{
//set Flag for left
}
else if([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)
{
//set Flag for right
}
您还可以赶上的通知时,该设备采用旋转:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectOrientation) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
,然后写一个方法detectOrientation
像这样:
-(void) detectOrientation
{
if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft)
{
//Set up left
} else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)
{
//Set up Right
} else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown)
{
//It's portrait time!
}
}
如果不缓存以前的方向值,这似乎不可能。到willAnimateRotationToInterfaceOrientation时:被称为接口和设备方向已经更新,这意味着任何方向已经失去了我对它感兴趣的点。 – ima747 2012-07-25 20:08:40