您可以檢查設備的方向,然後設置一個標誌,確定您處於左側還是右側。然後,當您的設備切換時,您可以抓住它並根據需要進行處理。
要確定方向使用:
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