/// <summary> /// Returns whether a certain touch is within the area that should /// activate the pan gesture sliding out the menu. /// </summary> /// <param name="touch"></param> /// <param name="sidebar"></param> /// <returns></returns> public virtual bool TouchInActiveArea(UITouch touch, Sidebar sidebar) { var view = ContentViewController.View; var position = touch.LocationInView(view).X; var area = sidebar.GestureActiveArea; return(sidebar.MenuLocation == MenuLocations.Left ? position <area : position> (view.Bounds.Width - area)); }
public void Pan(Sidebar sidebar) { if (sidebar.PanGesture.State == UIGestureRecognizerState.Began) { PanBegan(sidebar.PanGesture, sidebar.MenuLocation, sidebar.GestureActiveArea); } else if (!_ignorePan && (sidebar.PanGesture.State == UIGestureRecognizerState.Changed)) { PanChanged(sidebar); } else if (!_ignorePan && (sidebar.PanGesture.State == UIGestureRecognizerState.Ended || sidebar.PanGesture.State == UIGestureRecognizerState.Cancelled)) { PanEnded(sidebar); } }
private void PanChanged(Sidebar sidebar) { var xDelta = sidebar.PanGesture.TranslationInView(ContentViewController.View).X; if (sidebar.MenuLocation == MenuLocations.Left) { PanChangedMenuLeft(sidebar.MenuWidth, sidebar.IsOpen, xDelta); } else if (sidebar.MenuLocation == MenuLocations.Right) { PanChangedMenuRight(sidebar.MenuWidth, sidebar.IsOpen, xDelta); } ShowShadowWhileDragging(sidebar.HasShadowing, sidebar.MenuLocation); }
private void PanEndedTowardClose(Sidebar sidebar) { if (ContentViewController.View.Frame.X > -ContentViewController.View.Frame.Width / 2) { sidebar.CloseMenu(); } else { UIView.Animate( Sidebar.SlideSpeed, 0, UIViewAnimationOptions.CurveEaseInOut, () => { CloseAnimation(); HideDarkOverlay(); }, () => { }); } }
public void Pan(Sidebar sidebar) { if (sidebar.PanGesture.State == UIGestureRecognizerState.Began) { PanBegan(); } else if (sidebar.PanGesture.State == UIGestureRecognizerState.Changed) { PanChanged(sidebar); } else if (sidebar.PanGesture.State == UIGestureRecognizerState.Ended || sidebar.PanGesture.State == UIGestureRecognizerState.Cancelled) { PanEnded(sidebar); } }
/// <summary> /// Contructor. /// </summary> /// <param name="rootViewController"> /// The view controller that the Sidebar is being added to. /// </param> /// <param name="contentViewController"> /// The view controller for the content area. /// </param> /// <param name="navigationViewController"> /// The view controller for the side menu. /// </param> public SidebarController( UIViewController rootViewController, UIViewController contentViewController, UIViewController menuViewController) { _sidebar = new Sidebar(rootViewController, contentViewController, menuViewController); _sidebar.StateChangeHandler += (sender, e) => { if (StateChangeHandler != null) StateChangeHandler.Invoke(sender, e); }; ChangeMenuView(menuViewController); ChangeContentView(contentViewController); AttachSidebarControllerToRootController(rootViewController); }
/// <summary> /// Contructor. /// </summary> /// <param name="rootViewController"> /// The view controller that the Sidebar is being added to. /// </param> /// <param name="contentViewController"> /// The view controller for the content area. /// </param> /// <param name="navigationViewController"> /// The view controller for the side menu. /// </param> public SidebarController( UIViewController rootViewController, UIViewController contentViewController, UIViewController menuViewController) { _sidebar = new Sidebar(rootViewController, contentViewController, menuViewController); _sidebar.StateChangeHandler += (sender, e) => { if (StateChangeHandler != null) { StateChangeHandler.Invoke(sender, e); } }; ChangeMenuView(menuViewController); ChangeContentView(contentViewController); AttachSidebarControllerToRootController(rootViewController); }
private void PanEndedTowardClose(Sidebar sidebar) { if (ContentViewController.View.Frame.X > -ContentViewController.View.Frame.Width / 2) { sidebar.CloseMenu(); } else { UIView.Animate( Sidebar.SlideSpeed, 0, UIViewAnimationOptions.CurveEaseInOut, () => { CloseAnimation(); }, () => { }); } }
private void PanEnded(Sidebar sidebar) { var xDelta = sidebar.PanGesture.TranslationInView(ContentViewController.View).X; var velocity = sidebar.PanGesture.VelocityInView(ContentViewController.View).X; if ((sidebar.MenuLocation == MenuLocations.Left && sidebar.IsOpen && xDelta < 0) || (sidebar.MenuLocation == MenuLocations.Right && sidebar.IsOpen && xDelta > 0)) { PanEndedTowardClose(sidebar); } var flungOpenFromLeft = (sidebar.MenuLocation == MenuLocations.Left && (velocity > sidebar.FlingVelocity || ContentViewController.View.Frame.X > (sidebar.MenuWidth * sidebar.FlingPercentage))); var flungOpenFromRight = (sidebar.MenuLocation == MenuLocations.Right && (velocity < -sidebar.FlingVelocity || ContentViewController.View.Frame.X < -(sidebar.MenuWidth * sidebar.FlingPercentage))); if (flungOpenFromLeft || flungOpenFromRight) { sidebar.OpenMenu(); } else { UIView.Animate( Sidebar.SlideSpeed, 0, UIViewAnimationOptions.CurveEaseInOut, () => { ContentViewController.View.Frame = new RectangleF(0, 0, ContentViewController.View.Frame.Width, ContentViewController.View.Frame.Height); }, () => {}); } }
public SlideoutPanDelegate(Sidebar sidebar) { _sidebar = sidebar; }