나는 장치가 자신의 방향을 변경할 때 인식 아래이 코드를 가지고 있고, 방향이있는 경우 풍경을 왼쪽 또는 오른쪽으로, 그는 다시 세로로 :방향은 두 번째 시간에 변경되지 않는
[[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"];
}
}
내 프로젝트를 실행하고 내 장치의 방향을 가로 또는 세로로 변경하면이 코드는 방향을 인식하여 세로 방향으로 변경하지만 가로 또는 세로로 다시 장치를 회전하면 코드가 작동하지 않고 장치가 그대로 유지됩니다. 가로 모드에서, 왜? 이 문제를 해결하는 방법은 무엇입니까?