void LayoutSubviews(UIInterfaceOrientation theOrientation, bool animate) { // this is mostly for video playback. if a video is playing, we need // to make sure that it remains on the top when a rotation occurs UIView topView = null; if (View.Subviews.Count() > 0) { topView = View.Subviews.Last(); } if (_reconfigurePopup) { ReconfigureForMasterInPopover(!ShouldShowMaster(theOrientation)); } // Layout the master, detail and divider views appropriately, adding/removing subviews as needed. // First obtain relevant geometry. CGSize fullSize = SplitViewSizeForOrientation(theOrientation); nfloat width = fullSize.Width; nfloat height = fullSize.Height; // Layout the master, divider and detail views. CGRect newFrame = new CGRect(0, 0, width, height); UIView view; bool shouldShowMaster = ShouldShowMaster(theOrientation); bool masterFirst = MasterBeforeDetail; CGRect masterRect, dividerRect, detailRect; if (Vertical) { if (masterFirst) { if (!ShouldShowMaster()) { // Move off-screen. newFrame.X -= (SplitPosition + SplitWidth); } newFrame.Width = SplitPosition; masterRect = newFrame; newFrame.X += newFrame.Width; newFrame.Width = SplitWidth; dividerRect = newFrame; newFrame.X += newFrame.Width; newFrame.Width = width - newFrame.X; detailRect = newFrame; } else { if (!ShouldShowMaster()) { // Move off-screen. newFrame.Width += (SplitPosition + SplitWidth); } newFrame.Width -= (SplitPosition + SplitWidth); detailRect = newFrame; newFrame.X += newFrame.Width; newFrame.Width = SplitWidth; dividerRect = newFrame; newFrame.X += newFrame.Width; newFrame.Width = SplitPosition; masterRect = newFrame; } // Position master. view = _masterViewController.View; if (view != null) { view.Frame = masterRect; if (view.Superview == null) { _masterViewController.ViewWillAppear(false); View.AddSubview(view); _masterViewController.ViewDidAppear(false); } } // Position divider. view = DividerView; view.Frame = dividerRect; if (view.Superview == null) { View.AddSubview(view); } // Position detail. view = _detailViewController.View; if (view != null) { view.Frame = detailRect; if (view.Superview == null) { View.InsertSubviewAbove(view, _masterViewController.View); } else { View.BringSubviewToFront(view); } } } else { if (masterFirst) { if (!ShouldShowMaster()) { // Move off-screen. newFrame.Y -= (SplitPosition + SplitWidth); } newFrame.Height = SplitPosition; masterRect = newFrame; newFrame.Y += newFrame.Height; newFrame.Height = SplitWidth; dividerRect = newFrame; newFrame.Y += newFrame.Height; newFrame.Height = height - newFrame.Y; detailRect = newFrame; } else { if (!ShouldShowMaster()) { // Move off-screen. newFrame.Height += (SplitPosition + SplitWidth); } newFrame.Height -= (SplitPosition + SplitWidth); detailRect = newFrame; newFrame.Y += newFrame.Height; newFrame.Height = SplitWidth; dividerRect = newFrame; newFrame.Y += newFrame.Height; newFrame.Height = SplitPosition; masterRect = newFrame; } // Position master. view = _masterViewController.View; if (view != null) { view.Frame = masterRect; if (view.Superview == null) { _masterViewController.ViewWillAppear(false); View.AddSubview(view); _masterViewController.ViewDidAppear(false); } } // Position divider. view = DividerView; view.Frame = dividerRect; if (view.Superview == null) { View.AddSubview(view); } // Position detail. view = _detailViewController.View; if (view == null) { view.Frame = detailRect; if (view.Superview == null) { View.InsertSubviewAbove(view, _masterViewController.View); } else { View.BringSubviewToFront(view); } } } // Create corner views if necessary. MGSplitCornersView leadingCorners; // top/left of screen in Vertical/horizontal split. MGSplitCornersView trailingCorners; // bottom/right of screen in Vertical/horizontal split. if (_cornerViews == null) { leadingCorners = new MGSplitCornersView(); leadingCorners.SetSplitViewController(this); leadingCorners.CornerBackgroundColor = _defaultCornerColor; leadingCorners.CornerRadius = _defaultCornerRadius; trailingCorners = new MGSplitCornersView(); trailingCorners.SetSplitViewController(this); trailingCorners.CornerBackgroundColor = _defaultCornerColor; trailingCorners.CornerRadius = _defaultCornerRadius; _cornerViews = new MGSplitCornersView[2] { leadingCorners, trailingCorners }; } else { leadingCorners = _cornerViews[0]; trailingCorners = _cornerViews[1]; } // Configure and layout the corner-views. leadingCorners.CornersPosition = (Vertical) ? MGCornersPosition.LeadingVertical : MGCornersPosition.LeadingHorizontal; trailingCorners.CornersPosition = (Vertical) ? MGCornersPosition.TrailingVertical : MGCornersPosition.TrailingHorizontal; leadingCorners.AutoresizingMask = (Vertical) ? UIViewAutoresizing.FlexibleBottomMargin : UIViewAutoresizing.FlexibleRightMargin; trailingCorners.AutoresizingMask = (Vertical) ? UIViewAutoresizing.FlexibleTopMargin : UIViewAutoresizing.FlexibleLeftMargin; nfloat x, y, cornersWidth, cornersHeight; CGRect leadingRect, trailingRect; nfloat radius = leadingCorners.CornerRadius; if (Vertical) // left/right split { cornersWidth = (radius * 2.0f) + SplitWidth; cornersHeight = radius; x = ((shouldShowMaster) ? ((masterFirst) ? SplitPosition : width - (SplitPosition + SplitWidth)) : (0 - SplitWidth)) - radius; y = 0; leadingRect = new CGRect(x, y, cornersWidth, cornersHeight); // top corners trailingRect = new CGRect(x, (height - cornersHeight), cornersWidth, cornersHeight); // bottom corners } else // top/bottom split { x = 0; y = ((shouldShowMaster) ? ((masterFirst) ? SplitPosition : height - (SplitPosition + SplitWidth)) : (0 - SplitWidth)) - radius; cornersWidth = radius; cornersHeight = (radius * 2.0f) + SplitWidth; leadingRect = new CGRect(x, y, cornersWidth, cornersHeight); // left corners trailingRect = new CGRect((width - cornersWidth), y, cornersWidth, cornersHeight); // right corners } leadingCorners.Frame = leadingRect; trailingCorners.Frame = trailingRect; // Ensure corners are visible and frontmost. if (leadingCorners.Superview == null) { View.InsertSubviewAbove(leadingCorners, _detailViewController.View); View.InsertSubviewAbove(trailingCorners, _detailViewController.View); } else { View.BringSubviewToFront(leadingCorners); View.BringSubviewToFront(trailingCorners); } if (topView != null) { topView.Superview.BringSubviewToFront(topView); } // if (IsLandscape()) // View.Frame = new RectangleF(0, 20, View.Frame.Width, View.Frame.Height); // else // View.Frame = new RectangleF(0, 20, View.Frame.Width, View.Frame.Height); }
void LayoutSubviews(UIInterfaceOrientation theOrientation, bool animate) { // this is mostly for video playback. if a video is playing, we need // to make sure that it remains on the top when a rotation occurs UIView topView = null; if (View.Subviews.Count() > 0) topView = View.Subviews.Last(); if (_reconfigurePopup) { ReconfigureForMasterInPopover(!ShouldShowMaster(theOrientation)); } // Layout the master, detail and divider views appropriately, adding/removing subviews as needed. // First obtain relevant geometry. CGSize fullSize = SplitViewSizeForOrientation(theOrientation); nfloat width = fullSize.Width; nfloat height = fullSize.Height; // Layout the master, divider and detail views. CGRect newFrame = new CGRect(0, 0, width, height); UIView view; bool shouldShowMaster = ShouldShowMaster(theOrientation); bool masterFirst = MasterBeforeDetail; CGRect masterRect, dividerRect, detailRect; if (Vertical) { if (masterFirst) { if (!ShouldShowMaster()) { // Move off-screen. newFrame.X -= (SplitPosition + SplitWidth); } newFrame.Width = SplitPosition; masterRect = newFrame; newFrame.X += newFrame.Width; newFrame.Width = SplitWidth; dividerRect = newFrame; newFrame.X += newFrame.Width; newFrame.Width = width - newFrame.X; detailRect = newFrame; } else { if (!ShouldShowMaster()) { // Move off-screen. newFrame.Width += (SplitPosition + SplitWidth); } newFrame.Width -= (SplitPosition + SplitWidth); detailRect = newFrame; newFrame.X += newFrame.Width; newFrame.Width = SplitWidth; dividerRect = newFrame; newFrame.X += newFrame.Width; newFrame.Width = SplitPosition; masterRect = newFrame; } // Position master. view = _masterViewController.View; if (view != null) { view.Frame = masterRect; if (view.Superview == null) { _masterViewController.ViewWillAppear(false); View.AddSubview(view); _masterViewController.ViewDidAppear(false); } } // Position divider. view = DividerView; view.Frame = dividerRect; if (view.Superview == null) { View.AddSubview(view); } // Position detail. view = _detailViewController.View; if (view != null) { view.Frame = detailRect; if (view.Superview == null) { View.InsertSubviewAbove(view, _masterViewController.View); } else { View.BringSubviewToFront(view); } } } else { if (masterFirst) { if (!ShouldShowMaster()) { // Move off-screen. newFrame.Y -= (SplitPosition + SplitWidth); } newFrame.Height = SplitPosition; masterRect = newFrame; newFrame.Y += newFrame.Height; newFrame.Height = SplitWidth; dividerRect = newFrame; newFrame.Y += newFrame.Height; newFrame.Height = height - newFrame.Y; detailRect = newFrame; } else { if (!ShouldShowMaster()) { // Move off-screen. newFrame.Height += (SplitPosition + SplitWidth); } newFrame.Height -= (SplitPosition + SplitWidth); detailRect = newFrame; newFrame.Y += newFrame.Height; newFrame.Height = SplitWidth; dividerRect = newFrame; newFrame.Y += newFrame.Height; newFrame.Height = SplitPosition; masterRect = newFrame; } // Position master. view = _masterViewController.View; if (view != null) { view.Frame = masterRect; if (view.Superview == null) { _masterViewController.ViewWillAppear(false); View.AddSubview(view); _masterViewController.ViewDidAppear(false); } } // Position divider. view = DividerView; view.Frame = dividerRect; if (view.Superview == null) { View.AddSubview(view); } // Position detail. view = _detailViewController.View; if (view == null) { view.Frame = detailRect; if (view.Superview == null) { View.InsertSubviewAbove(view, _masterViewController.View); } else { View.BringSubviewToFront(view); } } } // Create corner views if necessary. MGSplitCornersView leadingCorners; // top/left of screen in Vertical/horizontal split. MGSplitCornersView trailingCorners; // bottom/right of screen in Vertical/horizontal split. if (_cornerViews == null) { leadingCorners = new MGSplitCornersView(); leadingCorners.SetSplitViewController(this); leadingCorners.CornerBackgroundColor = _defaultCornerColor; leadingCorners.CornerRadius = _defaultCornerRadius; trailingCorners = new MGSplitCornersView(); trailingCorners.SetSplitViewController(this); trailingCorners.CornerBackgroundColor = _defaultCornerColor; trailingCorners.CornerRadius = _defaultCornerRadius; _cornerViews = new MGSplitCornersView[2]{leadingCorners, trailingCorners}; } else { leadingCorners = _cornerViews[0]; trailingCorners = _cornerViews[1]; } // Configure and layout the corner-views. leadingCorners.CornersPosition = (Vertical) ? MGCornersPosition.LeadingVertical : MGCornersPosition.LeadingHorizontal; trailingCorners.CornersPosition = (Vertical) ? MGCornersPosition.TrailingVertical : MGCornersPosition.TrailingHorizontal; leadingCorners.AutoresizingMask = (Vertical) ? UIViewAutoresizing.FlexibleBottomMargin : UIViewAutoresizing.FlexibleRightMargin; trailingCorners.AutoresizingMask = (Vertical) ? UIViewAutoresizing.FlexibleTopMargin : UIViewAutoresizing.FlexibleLeftMargin; nfloat x, y, cornersWidth, cornersHeight; CGRect leadingRect, trailingRect; float radius = leadingCorners.CornerRadius; if (Vertical) { // left/right split cornersWidth = (radius * 2.0f) + SplitWidth; cornersHeight = radius; x = ((shouldShowMaster) ? ((masterFirst) ? SplitPosition : width - (SplitPosition + SplitWidth)) : (0 - SplitWidth)) - radius; y = 0; leadingRect = new CGRect(x, y, cornersWidth, cornersHeight); // top corners trailingRect = new CGRect(x, (height - cornersHeight), cornersWidth, cornersHeight); // bottom corners } else { // top/bottom split x = 0; y = ((shouldShowMaster) ? ((masterFirst) ? SplitPosition : height - (SplitPosition + SplitWidth)) : (0 - SplitWidth)) - radius; cornersWidth = radius; cornersHeight = (radius * 2.0f) + SplitWidth; leadingRect = new CGRect(x, y, cornersWidth, cornersHeight); // left corners trailingRect = new CGRect((width - cornersWidth), y, cornersWidth, cornersHeight); // right corners } leadingCorners.Frame = leadingRect; trailingCorners.Frame = trailingRect; // Ensure corners are visible and frontmost. if (leadingCorners.Superview == null) { View.InsertSubviewAbove(leadingCorners, _detailViewController.View); View.InsertSubviewAbove(trailingCorners, _detailViewController.View); } else { View.BringSubviewToFront(leadingCorners); View.BringSubviewToFront(trailingCorners); } if (topView != null) { topView.Superview.BringSubviewToFront(topView); } // if (IsLandscape()) // View.Frame = new RectangleF(0, 20, View.Frame.Width, View.Frame.Height); // else // View.Frame = new RectangleF(0, 20, View.Frame.Width, View.Frame.Height); }