2012-09-05 1 views
2

TabBarController에서 3 개의 탭이있는 응용 프로그램이 있습니다. 첫 번째 탭에서 사용자가 NavigationBar의 버튼을 누르면 바로 세로에서 가로로 회전 할 수 있습니까? 사용자가 처음으로 버튼을 누를 때만 회전 할 수 없습니다.UIBarButtonItem을 누를 때까지 방향 (회전)을 활성화/비활성화하는 방법은 무엇입니까?

SDK iOS 6을 사용하고 있습니다.

미리 감사드립니다.

+0

누구의 회전 ru 얘기? –

+0

@Prince 죄송합니다, 초상화에서 경치. –

답변

5
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 

    // Return YES for supported orientations 
    return allowedToRotate; 

} 

그러면 클래스 헤더에 BOOL allowedToRotate;이 있고 회전하려는 경우 YES로 설정하십시오. 당신이 아이폰 OS 6에있는 경우 : 나는 그것을 시도하지 않은 있지만, 작업을해야

-(NSUInteger)supportedInterfaceOrientations { 

    if (allowedToRotate) 
     return UIInterfaceOrientationMaskAll; 
    else 
     return UIInterfaceOrientationMaskPortrait; 

} 

...

+0

XCode는 iOS 6에서는'shouldAutorotateToInterfaceOrientation :'이 더 이상 사용되지 않습니다. 그러나 그 코드를 시도했지만 작동하지 않습니다. 나는'돌아 오는 NO '를 설정하고 난 여전히 풍경으로 회전합니다. –

+0

O yes iOS 6가 변경되었습니다. 답변을 업데이트했습니다 ... (실제로 시도하지 않았습니다 ...) – jjv360

+0

제 경우에는 supportedInterfaceOrientations 메소드가 올바르게 호출되고 UIInterfaceOrientationMaskPortrait가 반환됩니다. 그러나 장치를 회전하면 사용자 인터페이스도 함께 회전합니다. 왜 ? – aneuryzm

2

이는 가장 좋은 방법 확실하지 ... 나를 위해 속임수를 썼는지 .. .. 작동하지만 :

-(BOOL) shouldAutorotate { 

// Return YES for supported orientations 
return NO; 

} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { 
//Setting the orientation of the view. Ive set it to portrait here. 

return UIInterfaceOrientationPortrait; 

} 
+0

이것도 나를 위해 일했습니다. thnx :) – deltaaruna

+0

CustomControllerView.m 파일에이 메서드를 그냥 겹쳐 쓰면됩니까? 나를 위해 일하지 않았다 ... –

관련 문제