private void PresentMenuViewContainerWithMenuViewController(UIViewController menuViewController) { _menuViewContainer.Transform = CGAffineTransform.MakeIdentity(); if (ScaleBackgroundImageView) { _backgroundImageView.Transform = CGAffineTransform.MakeIdentity(); _backgroundImageView.Frame = View.Bounds; } _menuViewContainer.Frame = View.Bounds; if (ScaleMenuView) { _menuViewContainer.Transform = MenuViewControllerTransformation; } _menuViewContainer.Alpha = !FadeMenuView ? 1 : 0; if (ScaleBackgroundImageView) { _backgroundImageView.Transform = CGAffineTransform.MakeScale(1.7f, 1.7f); } WillShowMenuViewController?.Invoke(this, menuViewController); }
private void PanGestureRecognized(UIPanGestureRecognizer recognizer) { DidRecognizePanGesture?.Invoke(this, recognizer); if (!PanGestureEnabled) { return; } try { var point = recognizer.TranslationInView(View); if (recognizer.State == UIGestureRecognizerState.Began) { UpdateContentViewShadow(); _originalPoint = new CGPoint(_contentViewContainer.Center.X - _contentViewContainer.Bounds.Width / 2.0, _contentViewContainer.Center.Y - _contentViewContainer.Bounds.Height / 2.0); _menuViewContainer.Transform = CGAffineTransform.MakeIdentity(); if (ScaleBackgroundImageView) { _backgroundImageView.Transform = CGAffineTransform.MakeIdentity(); _backgroundImageView.Frame = View.Bounds; } _menuViewContainer.Frame = View.Bounds; AddContentButton(); View.Window.EndEditing(true); _didNotifyDelegate = false; } if (recognizer.State == UIGestureRecognizerState.Changed) { nfloat delta = 0; if (_visible) { delta = _originalPoint.X != 0 ? (point.X + _originalPoint.X) / _originalPoint.X : 0; } else { delta = point.X / View.Frame.Width; } delta = Math.Min(Math.Abs((float)delta), 1.6f); var contentViewScale = ScaleContentView ? 1 - ((1 - ContentViewScaleValue) * delta) : 1; var backgroundViewScale = 1.7f - (0.7f * delta); var menuViewScale = 1.5f - (0.5f * delta); if (!BouncesHorizontally) { contentViewScale = Math.Max((float)contentViewScale, ContentViewScaleValue); backgroundViewScale = Math.Max((float)backgroundViewScale, 1.0f); menuViewScale = Math.Max((float)menuViewScale, 1.0f); } _menuViewContainer.Alpha = !FadeMenuView ? 0 : delta; _contentViewContainer.Alpha = 1 - (1 - ContentViewFadeOutAlpha) * delta; if (ScaleBackgroundImageView) { _backgroundImageView.Transform = CGAffineTransform.MakeScale(backgroundViewScale, backgroundViewScale); } if (ScaleMenuView) { _menuViewContainer.Transform = CGAffineTransform.MakeScale(menuViewScale, menuViewScale); } if (ScaleBackgroundImageView) { if (backgroundViewScale < 1) { _backgroundImageView.Transform = CGAffineTransform.MakeIdentity(); } } if (!BouncesHorizontally && _visible) { if (_contentViewContainer.Frame.X > _contentViewContainer.Frame.Width / 2.0) { point.X = Math.Min(0.0f, (float)point.X); } if (_contentViewContainer.Frame.X < -(_contentViewContainer.Frame.Width / 2.0)) { point.X = Math.Max(0.0f, (float)point.X); } } // Limit size // if (point.X < 0) { point.X = Math.Max((float)point.X, (float)-UIScreen.MainScreen.Bounds.Height); } else { point.X = Math.Min((float)point.X, (float)UIScreen.MainScreen.Bounds.Height); } recognizer.SetTranslation(point, View); if (!_didNotifyDelegate) { if (point.X > 0) { if (!_visible) { _menuState = MenuState.LeftOpening; WillShowMenuViewController?.Invoke(this, LeftMenuViewController); } else { _menuState = MenuState.RightClosing; } } if (point.X < 0) { if (!_visible) { _menuState = MenuState.RightOpening; WillShowMenuViewController?.Invoke(this, RightMenuViewController); } else { _menuState = MenuState.LeftClosing; } } _didNotifyDelegate = true; } if (contentViewScale > 1) { var oppositeScale = (1 - (contentViewScale - 1)); _contentViewContainer.Transform = CGAffineTransform.MakeScale(oppositeScale, oppositeScale); _contentViewContainer.Transform = CGAffineTransform.Translate(_contentViewContainer.Transform, point.X, 0); } else { _contentViewContainer.Transform = CGAffineTransform.MakeScale(contentViewScale, contentViewScale); _contentViewContainer.Transform = CGAffineTransform.Translate(_contentViewContainer.Transform, point.X, 0); } if (LeftMenuViewController != null) { LeftMenuViewController.View.Hidden = _contentViewContainer.Frame.X < 0; } if (RightMenuViewController != null) { RightMenuViewController.View.Hidden = _contentViewContainer.Frame.X > 0; } if (LeftMenuViewController == null && _contentViewContainer.Frame.X > 0) { _contentViewContainer.Transform = CGAffineTransform.MakeIdentity(); _contentViewContainer.Frame = View.Bounds; _visible = false; LeftMenuVisible = false; } else if (RightMenuViewController == null && _contentViewContainer.Frame.X < 0) { _contentViewContainer.Transform = CGAffineTransform.MakeIdentity(); _contentViewContainer.Frame = View.Bounds; _visible = false; RightMenuVisible = false; } StatusBarNeedsAppearanceUpdate(); } if (recognizer.State == UIGestureRecognizerState.Ended) { _didNotifyDelegate = false; if (PanMinimumOpenThreshold > 0 && ( (_contentViewContainer.Frame.X < 0 && _contentViewContainer.Frame.X > -((int)PanMinimumOpenThreshold)) || (_contentViewContainer.Frame.X > 0 && _contentViewContainer.Frame.X < PanMinimumOpenThreshold)) ) { HideMenuViewController(); } else if (_contentViewContainer.Frame.X == 0) { HideMenuViewControllerAnimated(false); } else { if (recognizer.VelocityInView(View).X > 0) { if (_contentViewContainer.Frame.X < 0) { HideMenuViewController(); } else { if (LeftMenuViewController != null) { ShowLeftMenuViewController(); } } } else { if (_contentViewContainer.Frame.X < 20) { if (RightMenuViewController != null) { ShowRightMenuViewController(); } } else { HideMenuViewController(); } } } } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Exception :" + e); System.Diagnostics.Debug.WriteLine("Stacktrace :" + e.StackTrace); } }