我有下面這段代碼,當設備改變自己的方向承認,如果方向是橫向向左或向右,他再次回到肖像:方向不第二次改變
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:[UIDevice currentDevice]];
- (void) orientationChanged:(NSNotification *)note{
UIDevice * device = note.object;
if(device.orientation == UIDeviceOrientationLandscapeRight){
[[UIDevice currentDevice] setValue:
[NSNumber numberWithInteger: UIInterfaceOrientationPortrait]
forKey:@"orientation"];
}
if(device.orientation == UIDeviceOrientationLandscapeLeft){
[[UIDevice currentDevice] setValue:
[NSNumber numberWithInteger: UIInterfaceOrientationPortrait]
forKey:@"orientation"];
}
}
當我運行我的項目並將設備的方向改變爲左右風景,此代碼識別並將方向改爲肖像,但是如果我再次將設備旋轉到左右風景,則代碼不起作用,設備停留在風景模式下,爲什麼?以及如何解決這個問題?