我在我的应用程序中使用 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 启动时,默认动画(从左到右移动到父控制器)也会启动。结果是错误的组合。我怎样才能只运行一个(在 y 上平移)或制作自定义动画?