2012-10-30 3 views
0

보기가 나타날 때 장치 방향을 알고 싶습니다. 이전에는 shouldAutorotateToInterfaceOrientation 메서드를 사용할 수 있었지만 IOS 6에서는 더 이상 사용되지 않습니다.보기가 나타날 때 장치 방향을 알고 싶습니다. IOS 6

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 

    if (interfaceOrientation==UIInterfaceOrientationPortrait ||interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown) { 
     DashBtn.hidden=NO; 
    } 
    else 
    { 
     DashBtn.hidden=YES; 
     if (self.popoverControllerMain) { 
      [self.popoverControllerMain dismissPopoverAnimated:YES]; 
     } 


    } 
    return YES; 
} 

나는

(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 

이를 참조

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

대신 rootviewcontroller 및

- (BOOL)shouldAutorotate { 
    return NO; 
}// this method is not called 

- (NSUInteger)supportedInterfaceOrientations { 
    return UIInterfaceOrientationMaskPortrait; 
} 

답변

1

을 UINavigationController가의 카테고리를 만들고 코드 @implementation은 UINavigationController (Rotation_IOS6) 아래에 추가입니다 .viewControllers lastObject] shouldAutorotate]; }

- (NSUInteger) supportedInterfaceOrientations { 창 [self.viewControllers lastObject] supportedInterfaceOrientations]; }

  • (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation { 창 [self.viewControllers lastObject] preferredInterfaceOrientationForPresentation]; }

@end

1

사용 시도하고 모든 포스트 즉 체크 자세한 내용은을 참조하십시오. (BOOL) shouldAutorotate { 반환 [[자기 -

+0

하지만 ... 즉, 그것을 위해 장치를 – shyla

+0

@shyla를 회전하지 않고 첫 번째보기를로드하면'코드 작성해야 할 때 늘 전화 - (무효) viewDidLoad' 또는'- (void) viewWillAppear : (BOOL) animated' –

0

장치의 방향을 알 수있는 가장 좋은 방법은

[[UIApplication sharedApplication] statusBarOrientation] 
관련 문제