2017-11-14 7 views
0

이것은 iPhone에서만 작동하는 코드입니다. 두 기기에서 실행되는 범용 앱을 만들고있어 동일한 앱입니다.자동 회전 코드는 iPhone에서 작동하지만 iPad에서는 작동하지 않습니다.

**//Automatically rotates the view to landscape 
    let orientation: UIDeviceOrientation = UIDevice.current.orientation 
    //If landscape right the rotate right 
    if orientation == UIDeviceOrientation.landscapeLeft 
    { 
     UIView.animate(withDuration: 0.5, animations: 
      { 
       () -> Void in 
       let value = UIInterfaceOrientation.landscapeRight.rawValue 
       UIDevice.current.setValue(value, forKey: "orientation") 
     }) 


    } 
    else 
    { 
     UIView.animate(withDuration: 0.5, animations: 
      { 
       () -> Void in 
       let value = UIInterfaceOrientation.landscapeLeft.rawValue 
       UIDevice.current.setValue(value, forKey: "orientation") 
     }) 

    }** 

답변

0

여기 빌드 대상의 일반 탭에서 사용자가 확인하는 하나의 가능성 ... 프로젝트의 설정에서

,, 당신은 "장치"옵션을 선택 배포 정보 섹션 (즉있다 아마도 "유니버설"에있을 것입니다). 아래는 장치 방향 선택입니다. 흥미로운 기능이 하나 있습니다.

장치가 유니버셜에있을 때 일부 방향을 확인하면 설정이 iPhone 버전에만 적용됩니다. iPad로 장치 선택을 전환하면 옵션이 다를 수 있습니다. 선택을 iPhone으로 전환하고, 원하는 방향을 적용하고, iPad로 전환하고 방향을 다시 적용한 다음 최종적으로 장치를 Universal로 설정하십시오.

여기에 지원되지 않는 방향을 적용하려고하면 코드가 아무 것도하지 않는다는 직감이 있습니다.