Skip to content

Instantly share code, notes, and snippets.

@alexlau811
Created February 25, 2015 14:51
Show Gist options
  • Save alexlau811/e12a8c126e6e082a5017 to your computer and use it in GitHub Desktop.
Save alexlau811/e12a8c126e6e082a5017 to your computer and use it in GitHub Desktop.
A custom renderer to set custom animation for NavigationPage.PushAsync and NavigationPage.PopAsync on iOS with Xamarin Forms.
[assembly: ExportRenderer(typeof(NavigationPage), typeof(AnimationNavigationRenderer))]
class AnimationNavigationRenderer : NavigationRenderer
{
public override void PushViewController(UIViewController viewController, bool animated)
{
if (animated)
{
// Alternative way with different set of trannsition
/*
UIView.Animate(0.75, () =>
{
UIView.SetAnimationCurve(UIViewAnimationCurve.EaseInOut);
base.PushViewController(viewController, false);
UIView.SetAnimationTransition(UIViewAnimationTransition.CurlUp, this.View, false);
});
*/
var transition = CATransition.CreateAnimation();
transition.Duration = 0.75;
transition.Type = CAAnimation.TransitionPush;
View.Layer.AddAnimation(transition, null);
base.PushViewController(viewController, false);
}
else
{
base.PushViewController(viewController, false);
}
}
public override UIViewController PopViewController(bool animated)
{
if (animated)
{
// Alternative way with different set of trannsition
/* UIView.Animate(0.75, () =>
{
UIView.SetAnimationCurve(UIViewAnimationCurve.EaseInOut);
UIView.SetAnimationTransition(UIViewAnimationTransition.CurlDown, this.View, false);
});
*/
var transition = CATransition.CreateAnimation();
transition.Duration = 0.75;
transition.Type = CAAnimation.TransitionFromTop;
View.Layer.AddAnimation(transition, null);
return base.PopViewController(false);
}
else
{
return base.PopViewController(false);
}
}
}
Copy link

ghost commented Oct 11, 2017

can you please send the same code for android ?

@Suri12345
Copy link

Can you Please send the same code for Android..
Mail id:[email protected]

@Suri12345
Copy link

Can you Please send me the code for Android..
mail id:- [email protected].

@gromovic
Copy link

Need help to make it work with Prism...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment