2011-11-17 4 views
0

세로보기와 가로보기 모두에서 표시 할 수있는보기가 필요합니다. 그러나 다른보기를로드 할 때 가로로 보기만하면됩니다.아이폰 개발 : 런타임에 방향을 고정시킬 방법이 있습니까?

세로보기 및 가로보기로 표시 할 수있는보기 컨트롤러 A.가 있습니다.이보기 컨트롤러는 App 대리인이 만듭니다.

뷰의 버튼을 클릭하면 가로로만 표시하려는 뷰 컨트롤러 B를 만들고 [A.view addSubView : B.view]와 같은 뷰를로드합니다.

장치를 회전하면 shouldAutorotateToInterfaceOrientation 함수가
컨트롤러 A에서만 호출됩니다. 컨트롤러 B.에서 함수를 설정 한 것과 관계없이 호출 할 수 없습니다. 기본보기에서 ... 좋아, 이것을 시도
을 :

첫 번째보기에

답변

5

,

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

업데이트로 설정해야합니다

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { 
    return Yes; 
} 

것을 그리고 두 번째보기로 확인 컨트롤러/앱 델리게이트, shouldAutorotateToInterfaceOrientation은 장치가 회전 할 때마다 실행되며 전역 수준 변수를 넣습니다.

.h 
@interface NavAppDelegate : NSObject <UIApplicationDelegate> { 
    Bool *isMain; 
} 

.m 
-(void)viewDidLoad { 
    isMain = Yes; 
} 
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { 
    if (isMain) { 
     return Yes; 
    } else { 
     return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
    } 
} 
// This bit is where you'll have to adapt it to how you change your views 
// but it's a basic idea. 
-(void)bitThatDoesTheViewChange:(viewController *) controller { 
    isMain = No; 

    *viewController = controller; 

    [viewController release]; 

    isMain = Yes; 
} 
+0

같은 뭔가가 나는 기능 – joe

+0

추가 조금 오버라이드 (override) 할 수있는 앱 위임하여 만든 경우에만 뷰 컨트롤러를 생각 전화 했어요이 될 수없는 두 번째 view.But의 기능을 설정 한 생각 더 많은, 당신의 문제를 도울 수 있습니다 ... 내 ObjectiveC 약간 녹슨,하지만이 작동합니다 생각합니다. – AndyD273

+0

그건 좋은 생각이야 – joe

관련 문제