我使用Xamarin.Forms创建了一个简单的应用程序,需要将导航设置为up&左下状态&右侧
如果您想要up&向下动画(不是自定义动画),您可以简单地使用Navigation.PushModalAsync(page)
来呈现页面。
此外,我刚刚写了一个自定义渲染器来更改iOS上的动画。
[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);
}
}
}
https://gist.github.com/alexlau811/e12a8c126e6e082a5017