ios - 如何更改 UI Navigation View ios 的默认动画持续时间?

标签 ios

 UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
 [navController setViewControllers: @[rootViewController] animated: YES];

我知道默认动画持续时间,但我想知道如何更改动画持续时间。

我的实际代码如下

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
 [navController setViewControllers: @[rootViewController] animated: YES];
 [self.revealViewController setFrontViewController:navController];
 [self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];

我们如何为上面的代码添加动画

最佳答案

来自文档:

  setViewControllers: animated:

If animations are enabled, this method decides which type of transition to perform based on whether the last item in the items array is already in the navigation stack. Only one transition is performed, but when that transition finishes, the entire contents of the stack are replaced with the new view controllers.

在这种情况下,没有本地方法来调用具有持续时间的动画。

您可以尝试将 CATransition 添加到导航 Controller 层,您可以根据需要更改过渡的持续时间。

您可以子类化导航 Controller 并执行以下操作:

    CATransition *transition = [CATransition animation];
    transition.duration = 0.3f;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionFade;
    [self.view.layer addAnimation:transition forKey:nil];
    [self setViewControllers: @[rootViewController] animated: YES];

你可以找到不同的动画集here:

关于ios - 如何更改 UI Navigation View ios 的默认动画持续时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34357399/

相关文章:

ios - 如何在 Swift 的新 View 中调用 segue?

ios - Sprite Kit,我的背景图片不会在设备上显示

ios - UITabBar 有问题

ios - CGRect Intersects Rect 在悬停时改变图像

iOS - 如何获得委托(delegate)类

ios - 从 JSQMessagesViewController 打开图像

ios - 是否可以使用 Phonegap 在 iOS 上实现视频自动播放?

ios - 圆形边框不能完美剪裁/遮蔽

ios - viewDidLoad 中未知的 Storyboard按钮

iOS 将 NSString 转换为 NSDate 始终为 nil