/// <summary> /// Displays the popover. /// </summary> /// <param name="hideFirst"><c>true</c> to hide previous popover; <c>false</c> otherwise.</param> public void DisplayPopover(bool hideFirst = false) { // If no popover to show if (this.Popover == null) { return; } // Get the screen dimensions var screenWidth = UIScreen.MainScreen.Bounds.Width; var screenHeight = UIScreen.MainScreen.Bounds.Height; // Get the base width and height float width = 400; float height = 300; // If no orientation if (this.orientation == null) { // Get the device orientation // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression if (MediaPickerDelegate.IsValidInterfaceOrientation(UIDevice.CurrentDevice.Orientation)) { this.orientation = UIDevice.CurrentDevice.Orientation; } else { this.orientation = MediaPickerDelegate.GetDeviceOrientation(this.viewController.InterfaceOrientation); } } // Get the screen size based on orientation float x; float y; if ((this.orientation == UIDeviceOrientation.LandscapeLeft) || (this.orientation == UIDeviceOrientation.LandscapeRight)) { y = (float)(screenWidth / 2) - (height / 2); x = (float)(screenHeight / 2) - (width / 2); } else { x = (float)(screenWidth / 2) - (width / 2); y = (float)(screenHeight / 2) - (height / 2); } // hide the previous popover if (hideFirst && this.Popover.PopoverVisible) { this.Popover.Dismiss(false); } // Show a new popover this.Popover.PresentFromRect(new CGRect(x, y, width, height), this.viewController.View, 0, true); }
/// <summary> /// Called when the current device was rotated. /// </summary> /// <param name="notification">The device rotation notification.</param> private void DidRotate(NSNotification notification) { // Get the new device orientation var device = (UIDevice)notification.Object; if (!MediaPickerDelegate.IsValidInterfaceOrientation(device.Orientation) || (this.Popover == null)) { return; } // If new orientation is of the same kind if (this.orientation.HasValue && MediaPickerDelegate.IsSameOrientationKind(this.orientation.Value, device.Orientation)) { return; } // Get whether the view should be rotated if (UIDevice.CurrentDevice.CheckSystemVersion(6, 0)) { if (!this.GetShouldRotate6(device.Orientation)) { return; } } else if (!this.GetShouldRotate(device.Orientation)) { return; } // Get the current orientation var current = this.orientation; this.orientation = device.Orientation; if (current == null) { return; } // Display the new popover this.DisplayPopover(true); }