2012-08-02 2 views

답변

51

특정보기 컨트롤러에 방향 을 비활성화하려면 supportedInterfaceOrientationspreferredInterfaceOrientationForPresentation을 무시해야합니다.

- (NSUInteger) supportedInterfaceOrientations { // Return a bitmask of supported orientations. If you need more, // use bitwise or (see the commented return). return UIInterfaceOrientationMaskPortrait; // return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown; } - (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation { // Return the orientation you'd prefer - this is what it launches to. The // user can still rotate. You don't have to implement this method, in which // case it launches in the current orientation return UIInterfaceOrientationPortrait; } 

당신이 아이폰 OS 6 세 이상 뭔가를 대상으로하는 경우

, 당신은 shouldAutorotateToInterfaceOrientation: 방법을 원한다. '예'를 반환 할 때를 변경하면 해당 방향으로 회전할지 결정합니다. 이렇게하면 일반적인 세로 방향 만 허용됩니다.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 

    // Use this to allow upside down as well 
    //return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown); 
} 

shouldAutorotateToInterfaceOrientation:이는 아이폰 OS 6.0에서 더 이상 사용되지 않습니다.

+2

보기 contr oller가 내비게이션 컨트롤러에 있으면, 내비게이션 컨트롤러는 이들이 구현 될 필요가있는 곳이다. –

+0

@ MrRogers 나는 그렇게했지만 효과가 없다. http://pastebin.com/dLfLLP2j를 참조하십시오. 모든 컨트롤러는 supportedInterfaceOrientations를 올바르게 구현합니다. 첫 번째보기 컨트롤러는 iPhone Plus 홈 화면의 장치에서 앱을 실행해도 세로 방향으로 올바르게 표시됩니다. 그러나 다른 컨트롤러를 탐색 할 때 장치를 앞뒤로 돌려 다른 컨트롤러를 가로 방향으로 설정 한 다음 다시 돌아 오면 첫 번째 컨트롤러가 현재 가로 방향입니다. 내가 원하는 것은 첫 번째 컨트롤러가 초상화에 있고 두 번째 컨트롤러가 .all이되는 것입니다. –

+0

'supportedInterfaceOrientations' (첫 번째 코드 줄)에서'NSUinteger'를'UIInterfaceOrientationMask'로 재 배열 할 것을 제안합니다. Xcode 8은 "supportedInterfaceOrientations '의 구현에서 충돌하는 반환 유형에 대해 경고합니다.'UIInterfaceOrientationMask '(일명'enum UIInterfaceOrientationMask ')와'NSUInteger '(일명'unsigned long ')"를 비교하면 sens가됩니다. 답변 주셔서 감사합니다 – GabLeRoux

0

클래스에서 shouldAutorotateToInterfaceOrientation 메소드를 완전히 삭제해도 작동합니다. 회전을 계획하지 않는다면 클래스에 메서드를 포함하는 것은 의미가 없으며 코드가 적을수록 일을 깨끗하게 유지할 수 있습니다. 엑스 코드 4

+0

이 답변은 현재 사용되지 않습니다. 'shouldAutorotateToInterfaceOrientation'은 몇 년 동안 사용되지 않았습니다. –

+0

@MarkAmery https://developer.apple.com/reference/uikit/uiviewcontroller/1621419-shouldautorotate에는 지원 중단 알림이 없습니다. –

+0

@ VaddadiKartick 또한이 답변에서 언급 한 방법과는 다른 방법입니다. 나는 당신의 요점이 무엇인지 확신 할 수 없다. –

28

를 놓친 사람들을 위해

아래 :

enter image description here

: 앱 (모든 컨트롤러의 메소드를 오버라이드 (override) 할 필요가 없습니다)를 통해 방향을 해결하기 위해 프로젝트 설정 화면을 사용할 수 있습니다

지원되는 인터페이스 방향을 전환하는 것만 큼 간단합니다. 왼쪽 패널> 앱 타겟> 요약 탭에서 프로젝트를 클릭하여 찾을 수 있습니다.

+0

이것은 더 이상 사용되지 않습니다. 이제 UI가 다릅니다. –

35

엑스 코드 5

  • 위는 일반 탭으로 프로젝트 설정
  • 이동을 열려면 왼쪽 사이드 바에서 프로젝트 네비게이터에서 프로젝트를 클릭합니다. 이 같은 장치 방향에서 당신이 배포 정보 섹션에서 원하지 않는
  • 의 선택을 취소 옵션은

screenshot showing where to click

+1

광산에서 풍경을 선택 취소 할 수 없습니다. 그것은 즉시 그들을 다시 켭니다. 또한 Info.plist에서 삭제하면 다시 되돌립니다. – Almo

0

스위프트 3 당신이있는 navigationController가있는 경우, 서브 클래스를 (인물 사진 전용) :

class CustomNavigationViewController: UINavigationController { 

    override var supportedInterfaceOrientations: UIInterfaceOrientationMask { 
    return UIInterfaceOrientationMask.portrait 
    } 

    override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation { 
    return UIInterfaceOrientation.portrait 
    } 
} 
관련 문제