Skip to content
Browse files

Merge pull request #77 from Kestrel12/master

Added BeginAnimation EndAnimation and OpenChanged events
  • Loading branch information...
2 parents 50670be + c46cee2 commit 7fa46ddcdc41ebc616bbfa7394b92d792fa40146 @Clancey committed Jul 10, 2015
Showing with 62 additions and 8 deletions.
  1. +62 −8 FlyoutNavigation/FlyoutNavigationController.cs
View
70 FlyoutNavigation/FlyoutNavigationController.cs
@@ -287,7 +287,6 @@ void Initialize(UITableViewStyle navigationStyle = UITableViewStyle.Plain)
View.AddGestureRecognizer (openGesture = new UIScreenEdgePanGestureRecognizer(() => DragContentView (openGesture)){Edges = Position == FlyOutNavigationPosition.Left ? UIRectEdge.Left : UIRectEdge.Right});
View.AddGestureRecognizer (closeGesture = new OpenMenuGestureRecognizer (DragContentView, shouldReceiveTouch));
-
}
void CloseButtonTapped (object sender, EventArgs e)
{
@@ -336,6 +335,52 @@ public override void ViewDidLayoutSubviews()
}
}
+ public event EventHandler BeginAnimation;
+ public event EventHandler EndAnimation;
+ public event EventHandler OpenChanged;
+ private bool _prevIsOpen = false;
+
+ public class OpenChangedEventArgs : EventArgs
+ {
+ public OpenChangedEventArgs(bool isOpen){IsOpen = isOpen;}
+ public bool IsOpen { get; set; }
+ }
+
+ protected virtual void OnBeginAnimation(EventArgs e)
+ {
+ EventHandler handler = BeginAnimation;
+ if (handler != null)
+ {
+ handler (this, e);
+ }
+ }
+
+ protected virtual void OnEndAnimation(EventArgs e)
+ {
+ EventHandler handler = EndAnimation;
+ if(handler != null)
+ {
+ handler (this, e);
+ }
+ }
+
+ protected void CheckRaiseOpenChanged(){
+ OnEndAnimation (EventArgs.Empty);
+ if(_prevIsOpen != IsOpen){
+ OnOpenChanged (new OpenChangedEventArgs (IsOpen));
+ _prevIsOpen = IsOpen;
+ }
+ }
+
+ protected virtual void OnOpenChanged(OpenChangedEventArgs e)
+ {
+ EventHandler handler = OpenChanged;
+ if(handler != null)
+ {
+ handler (this, e);
+ }
+ }
+
public void DragContentView(UIGestureRecognizer gesture)
{
var panGesture = gesture as UIPanGestureRecognizer;
@@ -349,6 +394,7 @@ public void DragContentView(UIGestureRecognizer gesture)
var translation = panGesture.TranslationInView(View).X;
if (panGesture.State == UIGestureRecognizerState.Began)
{
+ OnBeginAnimation (EventArgs.Empty);
startX = frame.X;
}
else if (panGesture.State == UIGestureRecognizerState.Changed)
@@ -481,18 +527,25 @@ public void ShowMenu()
//menuBorder.Frame.Width = 1f;
View.InsertSubviewBelow(menuBorder, mainView);
}
- UIView.BeginAnimations("slideMenu");
+
+ });
+
+ OnBeginAnimation (EventArgs.Empty);
+ UIView.Animate(.2, () =>
+ {
UIView.SetAnimationCurve(UIViewAnimationCurve.EaseIn);
- //UIView.SetAnimationDuration(2);
- setViewSize();
CGRect frame = mainView.Frame;
frame.X = Position == FlyOutNavigationPosition.Left ? menuWidth : -menuWidth;
- SetLocation(frame);
setViewSize();
- frame = mainView.Frame;
+ SetLocation(frame);
shadowView.Frame = frame;
- UIView.CommitAnimations();
- });
+ }, showComplete);
+
+ }
+
+ void showComplete()
+ {
+ CheckRaiseOpenChanged ();
}
void setViewSize()
@@ -595,6 +648,7 @@ void hideComplete()
{
shadowView.RemoveFromSuperview();
navigation.View.Hidden = true;
+ CheckRaiseOpenChanged ();
}
public void ResignFirstResponders(UIView view)

3 comments on commit 7fa46dd

@insjinger

@Clancey -One thing i want to know i am not able to change your menuWidth which is 280. can u suggest me how to change those things...thanks in advance

@Clancey
Owner

Fork and change the value. For my purposes that width has always been perfect.

@insjinger

Thanks for Reply..

Please sign in to comment.
Something went wrong with that request. Please try again.