본문 바로가기

프로그래밍/iOS

[iOS] 디바이스 회전정보 받아오기

일단 회전잠금이 걸려있으면 절대 동작안한다.


1. 회전 감지 등록 제거 함수

- (void)registerDeviceOrientationNotification

{

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

    [[NSNotificationCenter defaultCenter] addObserver:selfselector:@selector(orientationChanged:)name:UIDeviceOrientationDidChangeNotification object:nil];

}


- (void)unregisterDeviceOrientationNotification

{

    [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];

    [[NSNotificationCenter defaultCenter] removeObserver:selfname:UIDeviceOrientationDidChangeNotification object:nil];

 

}


2. 회전감지 시 동작하는 함수

- (void) orientationChanged:(NSNotification *)notification

{

    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

    NSLog(@"orientationChanged:%d", (int)orientation);

}