2012-05-21 2 views
4

저는 iOS에 상당히 익숙하며 내 앱에서 오리엔테이션 변경 작업을 필사적으로 시도하고 있습니다. 연구 후 여기 내가하는 일 :iOS 방향 변경이 작동하지 않습니다. UIDeviceOrientationDidChangeNotification을받지 못했습니다.

내 앱에는 7 개의 UIViewController 하위 클래스를 관리하는 NavigationController가 있습니다.

프로젝트 요약 탭에서 나는 4 개의 모든 장치 방향을 활성화했습니다.

각 UIViewcontroller 하위 클래스에는 xib 파일이 있고 모든 xib 파일에는 "autoresize subviews"가 활성화되어 있습니다. UIViewController에 모든 서브 클래스

가 있습니다

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationPortrait || 
      interfaceOrientation == UIInterfaceOrientationLandscapeLeft || 
      interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
} 

또한 그들은 모두 있습니다

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 

과 : 측정 NSLog (...) 문 (결코 구현

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 

인쇄 된 디버거도 이러한 방법을 사용하지 않습니다.

또한 내가 사용하려고 시도했다 :

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 

BOOL getOrientationUpdates = [[UIDevice currentDevice] isGeneratingDeviceOrientationNotifications]; 
NSLog(@"will receive orientation notifications: %@", [email protected]"YES":@"NO"); 

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

-(void)orientationChanged: (NSNotification*) notification { NSLog(@"orientationChanged"); }

[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] removeObserver:self]; 각각. 내가 AppDelegate에의 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 방법 등 beginGeneratingDeviceOrientationNotifications을 수행 할 때

는 orientationChanged : 시작에 한 번이라고하지만 장치를 회전 그러나 결코 다시, 나는있는 UIViewController 중 하나에 그것을 할 때 호출되지 않습니다 서브 클래스!

지금까지 내가 달성하고 싶은 것은 UIImageView와 UIImage를 회전시키기위한 오리엔테이션 알림을 얻는 것입니다 (다른 방향으로 레이아웃을 변경하지 않고).

UIDeviceOrientation o = [UIDevice currentDevice].orientation; 

항상 UIDeviceOrientationPortrait

그것은 내가 워드 프로세서 나 유래에 뭔가를 놓친 수 있습니다 반환하지만 나는 분명히 내가해야 할 일/내 설정에서 작업을 진행하게 추가 알아낼 수 없습니다. 또한 나는 stackoverflow에 아주 익숙하다. 그래서 나는 내 게시물이 어떤 플랫폼 규칙에도 위배되지 않기를 바란다.

도움/의견을 보내 주시면 대단히 감사하겠습니다. 정말 고맙습니다!

EDIT : getOrientationUpdates는 항상 예 (YES)입니다. 회전 할 때 알림 콜백 선택기가 호출되지 않으므로 이상하게 보입니다!

편집 : 내 AppDelegate에의 didFinishLaunchingWithOptions에 내가 뭐하는 거지 :

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
self.regScreenController = [[RegistrationScreenController alloc] initWithNibName:@"RegistrationScreenController" bundle:nil]; 

navCtrl = [[UINavigationController alloc]initWithRootViewController:self.regScreenController]; 

[navCtrl setNavigationBarHidden:YES]; 
self.window.rootViewController = self.regScreenController; 
[self.window addSubview:navCtrl.view]; 
[self.window makeKeyAndVisible]; 
return YES; 

답변

5

을 당신이 당신의 AppDelegate'sdidFinishLaunchingWithOptionsself.window.rootViewController을 설정하는 경우를 참조하십시오 : 방법, 때문에 당신은 창 방향 변경 알림 만 하위 뷰를 추가하는 경우 해고하지 않는다.

+0

답변 해 주셔서 감사합니다. 내 편집을 보면 rootViewController를 설정하고 있는데 UINavigationController와 관련하여 잘못된 방식으로 수행하고 있습니까? 여전히 내가 무엇을 놓치고에 붙어 ... – robscure

+0

또는 다른 말로 표현 : 문제가 rootViewController와 관련된 경우, UINavigationController가 rootViewController로 초기화되고 UINavigationController를 창에 대한 서브 뷰로 설정하면 올바른 것입니까? UINavigationController의 rootViewController를 윈도우의 rootViewController로 설정하거나 오리엔테이션 변경 알림을 얻기 위해 여기에 연결하는 올바른 방법은 무엇입니까? 덕분에 많이 – robscure

+0

나는 그렇게 생각하지 않는다. 당신은 창에 어떤 하위 뷰도 추가하지 말아야한다. rootViewController를 설정하면 계층 구조의 다른 모든 항목은 rootViewController에서 시작해야합니다 (UINavigationController이지만 윈도우에 추가 된 하위 뷰는 없습니다). – graver

관련 문제