2016-11-11 2 views
1

타블 친화적 인 UI로 응용 프로그램을 확장하고 싶습니다. 전화 UI가 세로 방향에서 훨씬 잘 작동하므로 기존 앱이 세로로 고정됩니다. 태블릿 버전에는 이러한 제한이 없습니다.iOS 용 Xamarin Forms의 관용어 전용 장치 방향

이것은 Android에서 잘 작동합니다. 주 활동은 모든 기기 방향 (태블릿)을 허용할지 또는 앱을 세로 방향 (휴대 전화)으로 고정할지 여부를 결정합니다. 문제는 iOS에서도 오리엔테이션 논리를 구현하는 데 있습니다.

Xamarin.Forms에는 iOS 장치의 코드에서 장치 방향을 제어 할 수 없도록 bug이 있습니다. 우리는 가능한 해결책을 생각해 냈습니다. 모든 빌드 대상이 중복되었고 (전화 인스턴스 하나와 태블릿 인스턴스 하나), 전화 및 태블릿 빌드는 App Store에 별도로 업로드됩니다.

정말 관용구 고유의 장치 방향을 달성하는 가장 우아한 방법입니까, 아니면 Xamarin.Forms 버그를 많은 번거 로움없이 해결할 수있는 방법이 있습니까?

public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations(UIApplication application, UIWindow forWindow) 
    { 
     //Tablet orientation adjustment 
     if (Device.Idiom == TargetIdiom.Tablet) 
      return UIInterfaceOrientationMask.Landscape; 
     else 
      return UIInterfaceOrientationMask.Portrait; 
    } 

그런 다음 OnElementChangedMethodContentPage에 대한 인 CustomRenderer을 작성하고 우선

AppDelegate.cs :

protected override void OnElementChanged(VisualElementChangedEventArgs e) 
    { 
     base.OnElementChanged(e); 
     if (e.NewElement != null) 
     { 
      Page _page = Element as Page; 
      _page.Appearing += (s, ea) => 
      { 
       UIInterfaceOrientation orientain = Device.Idiom == TargetIdiom.Phone ? UIInterfaceOrientation.Portrait : UIInterfaceOrientation.LandscapeLeft; 

       NSNumber number = NSNumber.FromInt32((int)orientain); 
       UIDevice.CurrentDevice.SetValueForKey(number, new NSString("orientation")); 
       UIViewController.AttemptRotationToDeviceOrientation(); 
      }; 
     } 

    } 
다음

답변

관련 문제