如何禁用navigationBar动画?
我有两个 UITableViewController,这样当我在第一个 UITableViewController 上单击“下一步”时,第二个 UITableViewController 就会被推送到导航堆栈上并像平常一样对过渡进行动画处理。我想做到这一点,以便当我按下下一步时,只有视图有动画,而导航栏没有(保持不变)。我已经非常接近用下面的代码来做到这一点:
- (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 中完全相同。它几乎可以工作,问题是,动画发生时导航栏会闪烁。有没有办法让它不闪烁,或者有没有其他好的方法来防止导航栏的动画发生(即禁用图层上的动画或其他东西)?
更新:有人还有其他想法吗?仍在为此苦苦挣扎。
I have two UITableViewControllers such that when I click next on the first UITableViewController, the second UITableViewController gets pushed on the navigation stack and animates the transition like normal. I'd like to make it so when I push next, only the views animate, and the navigation bar doesn't (stays the same). I've gotten very close to doing this with the code below:
- (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];
}
I put this code, and I also make it so the title and buttons on both navigation bars are exactly same in each UITableViewController. It almost works, problem is, the navigation bar blinks when the animation occurs. Is there anyway to get it to not blink, or is there any other good way to prevent the animation of the navbar from occurring (ie disabling the animation on the layer or something)?
UPDATE: Anyone got any other ideas? Still struggling with this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这就是我想出来的。以下是序列中第一个视图控制器的代码:
这是第二个视图控制器的代码:
您必须使用
UINavigationController
委托方法来确定UIViewController
何时正在展示。然后,对于每个UIViewController
,需要创建一个BOOL
isInitialized
属性,以便它可以帮助您确定UIViewController
何时被初始化推入堆栈,或者当您推回下一个UIViewController
时显示它。This is what I came up with. Here is the code for the first viewController in the sequence:
Here is the code for the 2nd view controller:
You have to use the
UINavigationController
delegate methods to figure out when theUIViewController
is being shown. Then for eachUIViewController
, need to make aBOOL
isInitialized
property so it helps you determine when theUIViewController
is being pushed on the stack, or when it's being shown because you pushed back on the nextUIViewController
.这可能不是最好的答案/想法,但您可以在动画期间屏蔽 UINavigationBar。
创建一个看起来与当前
UNaviationBar
完全相同的UINavigationBar
,将其添加到keyWindow
中,在转换发生之前,然后在转换发生之后完成删除它。这基本上只覆盖UINavigationBar
并隐藏其动画。This may not be the best answer/idea but you could just mask the UINavigationBar during the animation.
Create a
UINavigationBar
that looks exactly the same way as your currentUNavigationBar
add it to thekeyWindow
just before the transition takes place, then after it is finished remove it. This will essentially cover just theUINavigationBar
and hide its animation.Swift
这是 swift 中的解决方案
您的 FirstViewController:
您的 SecondViewController:
Swift
Here is solution in swift
Your FirstViewController:
Your SecondViewController: