Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hossambarakat/6d3d8c4efa401aa9077c to your computer and use it in GitHub Desktop.
Save hossambarakat/6d3d8c4efa401aa9077c 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);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment