2014-10-14 1 views
0

가로 및 세로 모두 지원되어야하는 iPad 응용 프로그램을 작성하고 있습니다. 이 같은 AppDelegate에 루트보기 컨트롤러를 설정했습니다. 이보기는 내 스플래시 화면보기입니다.방향 변경 ipad를 감지하는 방법

내부

`

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 

    if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft) 
{ 
    //Do what you want in Landscape Left 
    viewController1=[[SplashLandscapeViewController alloc] initWithNibName:@"SplashLandscapeViewController" bundle:nil]; 
} 
else if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight) 
{ 
    //Do what you want in Landscape Right 
    viewController1=[[SplashLandscapeViewController alloc] initWithNibName:@"SplashLandscapeViewController" bundle:nil]; 
} 
else if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait) 
{ 
    //Do what you want in Portrait 
    viewController1=[[SplashLandscapeViewController alloc] initWithNibName:@"SplashViewController" bundle:nil]; 
} 
else if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown) 
{ 
    //Do what you want in Portrait Upside Down 
    viewController1=[[SplashLandscapeViewController alloc] initWithNibName:@"SplashViewController" bundle:nil]; 
} 





self.window.rootViewController = viewController1; 
[self.window makeKeyAndVisible]; 

return YES; 

}

그리고 이것이 잘 작동한다. 그리고이 viewcontroller1은 4,5 초 후에 닫히고 다른 viewcontroller를로드합니다. 내 문제는 그 viewcontroller1 화면에 표시하는 동안 사용자가 ipad를 어떻게 인식 할 수 있습니다 및 현재 가로 세로 xib 제거한 후 내 landscape .xib로드 할 수 있습니다.

도와주세요. 감사합니다.

답변

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

add this method into the app view controller for getting notification. 

-(void)changeOrientation { 
    UIDeviceOrientation orientation = [UIDevice currentDevice].orientation; 
    if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown) { 
     [[NSBundle mainBundle] loadNibNamed:@"Portrait" owner:self options:nil]; 
    } 
    else { 
     [[NSBundle mainBundle] loadNibNamed:@"Landscape" owner:self options:nil]; 
    } 

}