Beispiel #1
0
        static partial void SetOrientationPartial(DisplayOrientations orientations)
        {
            var currentOrientationMask = UIApplication.SharedApplication
                                         .StatusBarOrientation
                                         .ToUIInterfaceOrientationMask();

            var toOrientationMask = orientations.ToUIInterfaceOrientationMask();

            //If we are not already in one of the requested orientations, we need to force the application to rotate.
            if (!toOrientationMask.HasFlag(currentOrientationMask))
            {
                //Rotate to the most preferred orientation that is requested
                //e.g. if our mask is Portrait | PortraitUpsideDown, we prefer to intially rotate to Portrait rather than PortraitUpsideDown
                var toOrientation = PreferredOrientations.FirstOrDefault(ori => toOrientationMask.HasFlag(ori)).ToUIInterfaceOrientation();

                UIDevice.CurrentDevice
                .SetValueForKey(
                    new NSNumber((int)toOrientation),
                    new NSString("orientation")
                    );

                UIApplication.SharedApplication.SetStatusBarOrientation(toOrientation, false);
            }

            //Forces the rotation if the physical device is being held in an orientation that has now become supported
            UIViewController.AttemptRotationToDeviceOrientation();
        }
Beispiel #2
0
        public void SubscribePrismEvent()
        {
            IContainerProvider containerProvider = App.Current.Container;
            IEventAggregator   eventAggregator   = containerProvider.Resolve <IEventAggregator>();

            eventAggregator.GetEvent <CustomScreenOrientationEvent>().Subscribe(x =>
            {
                ScreenOrientation = x.CustomScreenOrientation;
                NSNumber n;
                NSString key = new NSString("orientation");
                if (x.CustomScreenOrientation == CustomScreenOrientation.Unspecified)
                {
                    n = new NSNumber((int)UIInterfaceOrientation.Unknown);
                }
                else if (x.CustomScreenOrientation == CustomScreenOrientation.UserPortrait)
                {
                    n = new NSNumber((int)UIInterfaceOrientation.Portrait);
                }
                else
                {
                    n = new NSNumber((int)UIInterfaceOrientation.LandscapeLeft);
                }
                UIDevice.CurrentDevice.SetValueForKey(
                    new NSNumber((int)n),
                    new NSString("orientation"));
                UIViewController.AttemptRotationToDeviceOrientation();

                DispatchQueue.MainQueue.DispatchAsync(() =>
                {
                });
            });
        }
 private void SetDeviceOrientation(DeviceOrientations orientation)
 {
     DispatchQueue.MainQueue.DispatchAsync(() =>
     {
         UIDevice.CurrentDevice.SetValueForKey(
             NSObject.FromObject(Convert(orientation)),
             new NSString("orientation"));
         UIViewController.AttemptRotationToDeviceOrientation();
     });
 }
Beispiel #4
0
        internal static void ResetDeviceOrientation(DeviceOrientation supportedOrientation)
        {
            switch (supportedOrientation)
            {
            case DeviceOrientation.AllLandscapes:
            case DeviceOrientation.LandscapeLeft:
                SetDeviceOrientation(UIInterfaceOrientation.LandscapeLeft);
                break;

            case DeviceOrientation.LandscapeRight:
                SetDeviceOrientation(UIInterfaceOrientation.LandscapeRight);
                break;

            case DeviceOrientation.AllPortraits:
            case DeviceOrientation.Portrait:
                SetDeviceOrientation(UIInterfaceOrientation.Portrait);
                break;

            case DeviceOrientation.PortraitUpsideDown:
                SetDeviceOrientation(UIInterfaceOrientation.PortraitUpsideDown);
                break;
            }
            UIViewController.AttemptRotationToDeviceOrientation();
        }