2016-08-16 2 views

답변

5

답변이 있습니다. 당신은 장치, 푸시의 ViewController를 회전하면 AppDelegate에서, ...이 기능은 항상 곁에

func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask 
{ 
    if self.restrictRotation { 
     return UIInterfaceOrientationMask.All 
    } 
    else { 
     return UIInterfaceOrientationMask.Landscape 
    } 
} 

restrictRotation 사용자 지정 매개 변수입니다 호출합니다. 기기가 회전하거나 viewController이 변경되면 사용자가 변경합니다. 대상에서

+0

여기에 'self.restrictRotation'은 무엇입니까? 그것은 어디에서 decleared입니까? –

+0

작성해야하는 매개 변수 인 @NileshPol. 장치를 회전하거나 UIViewController를 변경하기 전에 해당 함수가 호출됩니다. –

2

UIViewControllershouldAutorotatesupportedInterfaceOrientations을 입력하기 만하면됩니다. this documentation을보세요. 예 :

override func shouldAutorotate() -> Bool { 
    return true 
} 

사용할 수있는 방향을 지정할 수도 있습니다.

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { 
    return .Landscape 
} 

편집 : 당신이 국기에 대한 서로 다른 방향을 지원하려면 , 당신은 단지 같은 것을 할 필요가 :

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { 
    if myFlag { 
     return .Landscape 
    } else { 
     return .All 
    } 
} 

(myFlag 인 경우 여기에만 초상화 방향과 예입니다 사실, Landscape 방향을 허용합니다. 그렇지 않으면 모든 방향이 허용됩니다).

+0

완벽한 해답. 정말 고맙습니다. –

+0

스위프트 4와 함께 작동합니다. 감사합니다. – mkul

5

설정 장치 orientarion 초상화 -> 일반 -> 배포 정보 -> 세로

enter image description here

+0

이 답변에 적합합니다. 보기 컨트롤러에서 자동 회전을 재정의 할 수 있었던 것에 어떤 변화가 있었습니까? 그것은 함수였습니다. 이제는 var이고 시도해 보았을 때 아무런 효과가 없습니다 - 아직 만족할만한 대답을 찾을 수 없었습니다. – nbpeth

관련 문제