gpt4 book ai didi

ios - 如何禁用导航栏动画?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:08:36 26 4
gpt4 key购买 nike

我有两个 UITableViewController,这样当我在第一个 UITableViewController 上单击下一步时,第二个 UITableViewController 会被推送到导航堆栈上,并像往常一样为过渡设置动画。我想做到这一点,所以当我接下来按下时,只有 View 有动画,而导航栏没有(保持不变)。我已经非常接近于使用以下代码执行此操作:

- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];

CATransition *navTransition = [CATransition animation];
navTransition.duration = .5;
navTransition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
navTransition.type = kCATransitionPush;
navTransition.subtype = kCATransitionPush;
[self.navigationController.navigationBar.layer addAnimation:navTransition forKey:nil];

}

我放置了这段代码,并且我还制作了它,因此两个导航栏上的标题和按钮在每个 UITableViewController 中都完全相同。它几乎可以工作,问题是,动画出现时导航栏会闪烁。无论如何让它不闪烁,或者是否有任何其他好的方法来防止导航栏的动画发生(即禁用层上的动画或其他东西)?

更新:有人有任何其他想法吗?仍在为此苦苦挣扎。

最佳答案

这是我想出来的。这是序列中第一个 viewController 的代码:

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if (viewController == self)
{
if (self.isInitialized)
{
CATransition *navigationBarAnimation = [CATransition animation];
navigationBarAnimation.duration = 1.5;
navigationBarAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];;
navigationBarAnimation.type = kCATransitionFade;
navigationBarAnimation.subtype = kCATransitionFade;
navigationBarAnimation.removedOnCompletion = YES;
[self.navigationController.navigationBar.layer addAnimation:navigationBarAnimation forKey:nil];
}
else
{
self.isInitialized = YES;
}
}
}

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if (viewController == self)
{
if (self.isInitialized)
{
[self.navigationController.navigationBar.layer removeAllAnimations];
}
}
}

这是第二个 View Controller 的代码:

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if (viewController == self)
{
if (!self.isInitialized)
{
CATransition *navigationBarAnimation = [CATransition animation];
navigationBarAnimation.duration = 1.5;
navigationBarAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];;
navigationBarAnimation.type = kCATransitionFade;
navigationBarAnimation.subtype = kCATransitionFade;
navigationBarAnimation.removedOnCompletion = YES;
[self.navigationController.navigationBar.layer addAnimation:navigationBarAnimation forKey:nil];
self.isInitialized = YES;
}
}
}

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if (viewController == self)
{
if (self.isInitialized)
{
[self.navigationController.navigationBar.layer removeAllAnimations];
}
}
}

您必须使用 UINavigationController 委托(delegate)方法来确定何时显示 UIViewController。然后对于每个 UIViewController,需要创建一个 BOOL isInitialized 属性,这样它可以帮助您确定 UIViewController 何时被初始化插入堆栈,或者当它显示时,因为您推回了下一个 UIViewController

关于ios - 如何禁用导航栏动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8717742/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com