我有下面这段代码,当设备改变自己的方向承认,如果方向是横向向左或向右,他再次回到肖像:方向不第二次改变
[[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"];
}
}
当我运行我的项目并将设备的方向改变为左右风景,此代码识别并将方向改为肖像,但是如果我再次将设备旋转到左右风景,则代码不起作用,设备停留在风景模式下,为什么?以及如何解决这个问题?