我正在使用NavigationController在我的应用中导航。当PushViewController启动(someUIViewController,true)时,它会使用默认动画更改视图(从子控制器从右向左移动)。如何更改此动画?现在我使用的是:
this.NavigationController.PushViewController(someUIViewController,true);
UIView.BeginAnimations(null);
UIView.SetAnimationDuration(0.4);
UIView.SetAnimationTransition(UIViewAnimationTransition.FlipFromRight, NavigationController.View,true);
UIView.CommitAnimations();但是我被限制为四种UIViewAnimationTransition类型,我找到了我需要的(视图从下到上的外观):
this.NavigationController.PushViewController(someUIViewController,true);
var theAnimation = CABasicAnimation.FromKeyPath("transform.translation.y");
theAnimation.Duration = 0.3f;
theAnimation.From = NSNumber.FromFloat(this.View.Frame.Height);
theAnimation.To = NSNumber.FromFloat(0f);
NavigationController.View.Layer.AddAnimation(theAnimation, "animate");
NavigationController.View.Layer.AnimationForKey("animate");但是当CABasicAnimation启动时,默认动画(从左到右移动到父控制器)启动too.The结果是错误的combination.How我可以只运行一个(y上的平移)或创建自定义动画吗?
发布于 2012-10-13 06:31:02
我认为您需要将对PushViewController的调用更改为not animate,以避免默认动画生效。
this.NavigationController.PushViewController(someUIViewController,为真);
应该是
this.NavigationController.PushViewController(someUIViewController,false);
发布于 2014-02-28 16:42:30
也是同样的问题。对于这个问题,没有正常的解决方案。PushViewController受到标准动画(UIViewAnimationTransition类型)的限制。如果您想要更改它们,请尝试以下操作:
NavigationController.PushViewController(screen, false);
var theAnimation = CABasicAnimation.FromKeyPath("transform.translation.x");
theAnimation.Duration = 0.6f;
theAnimation.From = NSNumber.FromFloat(-NavigationController.View.Frame.Width);
theAnimation.To = NSNumber.FromFloat(0f);
NavigationController.View.Layer.AddAnimation(theAnimation, "animate");
NavigationController.View.Layer.AnimationForKey("animate"); 但它并不完美,试一试,你会明白为什么。你也可以使用PresentViewController。它在UIModalTransitionStyle中还有一些其他标准动画:
this.NavigationController.PresentViewController(new UINavigationController(screen){
ModalTransitionStyle= UIModalTransitionStyle.CoverVertical,
}, true,null);发布于 2014-02-28 16:51:54
//Allows a UINavigationController to push using a custom animation transition
public static void PushControllerWithTransition(this UINavigationController
target, UIViewController controllerToPush,
UIViewAnimationOptions transition)
{
UIView.Transition(target.View, 0.75d, transition, delegate() {
target.PushViewController(controllerToPush, false);
}, null);
}
//Allows a UINavigationController to pop a using a custom animation
public static void PopControllerWithTransition(this UINavigationController
target, UIViewAnimationOptions transition)
{
UIView.Transition(target.View, 0.75d, transition, delegate() {
target.PopViewControllerAnimated(false);
}, null);
}//有了这些扩展,现在使用翻转动画在控制器之间移动就像下面这样简单:
//Pushing someController to the top of the stack
NavigationController.PushControllerWithTransition(someController,
UIViewAnimationOptions.TransitionFlipFromLeft);
//Popping the current controller off the top of the stack
NavigationController.PopControllerWithTransition(
UIViewAnimationOptions.TransitionFlipFromRight);https://stackoverflow.com/questions/12038543
复制相似问题