首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >单点触控:如何使用NavigationController.PushViewController更改视图更改的默认动画

单点触控:如何使用NavigationController.PushViewController更改视图更改的默认动画
EN

Stack Overflow用户
提问于 2012-08-20 21:24:54
回答 3查看 2.8K关注 0票数 1

我正在使用NavigationController在我的应用中导航。当PushViewController启动(someUIViewController,true)时,它会使用默认动画更改视图(从子控制器从右向左移动)。如何更改此动画?现在我使用的是:

代码语言:javascript
复制
this.NavigationController.PushViewController(someUIViewController,true);
        UIView.BeginAnimations(null);
        UIView.SetAnimationDuration(0.4);
        UIView.SetAnimationTransition(UIViewAnimationTransition.FlipFromRight, NavigationController.View,true);
        UIView.CommitAnimations();

但是我被限制为四种UIViewAnimationTransition类型,我找到了我需要的(视图从下到上的外观):

代码语言:javascript
复制
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上的平移)或创建自定义动画吗?

EN

回答 3

Stack Overflow用户

发布于 2012-10-13 06:31:02

我认为您需要将对PushViewController的调用更改为not animate,以避免默认动画生效。

this.NavigationController.PushViewController(someUIViewController,为真);

应该是

this.NavigationController.PushViewController(someUIViewController,false);

票数 0
EN

Stack Overflow用户

发布于 2014-02-28 16:42:30

也是同样的问题。对于这个问题,没有正常的解决方案。PushViewController受到标准动画(UIViewAnimationTransition类型)的限制。如果您想要更改它们,请尝试以下操作:

代码语言:javascript
复制
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中还有一些其他标准动画:

代码语言:javascript
复制
this.NavigationController.PresentViewController(new UINavigationController(screen){ 
        ModalTransitionStyle= UIModalTransitionStyle.CoverVertical, 
}, true,null);
票数 0
EN

Stack Overflow用户

发布于 2014-02-28 16:51:54

代码语言:javascript
复制
//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);         
}

//有了这些扩展,现在使用翻转动画在控制器之间移动就像下面这样简单:

代码语言:javascript
复制
//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);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12038543

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档