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/