코딩하는 나귀

1) 통지 메세지 등록:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectOrientation) name:@"UIDeviceOrientationDidChangeNotification" object:nil];  

2) 통지 이벤트에 대한 처리 함수:

-(void) detectOrientation {
   
if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) ||
       
([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)) {
       
[self doLandscapeThings];
   
} else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait) {
       
[self doPortraitThings];
   
}  
}