我在我的字典应用程序中使用了一个定制的容器 View Controller 。基本上,容器 View Controller 在顶部包含一个自定义导航栏(不是 UINavigationBar
——只是一个带有后退和前进的
、UIView
UIButtonsUISearchBar
和右侧的书签 UIButton
)以及底部的标签栏 Controller 。
我的问题是:我使用后退和前进按钮在其中一个选项卡(UINavigationController
)中推送和弹出 View Controller ,以便用户可以浏览字典浏览历史记录。但是,如果我按下后退或前进按钮的速度太快,我会在日志 Pane 中收到此消息,并且某些屏幕根本不会出现:
Unbalanced calls to begin/end appearance transitions for <DefinitionViewController: 0x8e5d230>.
环顾 StackOverflow,我明白这是因为点击后退或前进按钮太快会调用事件选项卡中 UINavigatonController
的推送/弹出方法,但它不会让动画结束。 https://stackoverflow.com/a/17440074/855680
在没有动画的情况下推送或弹出 View Controller 可以解决问题,但我确实想保留动画。我该如何解决这个问题?我查看了 UINavigationController
类引用,看看是否有任何委托(delegate)方法或属性表明它在动画中间,但似乎没有。
最佳答案
我自己修好了。解决方案是在我的容器 View Controller 中创建一个属性,指示 UINavigationController
过渡动画是否仍在发生:
@property (nonatomic, getter = isStillAnimatingTransition) BOOL stillAnimatingTransition;
现在,对于我插入 UINavigationController
的所有 UIViewController
类,我将此标志设置为 YES
或 NO
在每个 View Controller 的 viewWillDisappear
和 viewDidAppear
方法中,像这样:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
self.containerViewController.stillAnimatingTransition = NO;
}
- (void)viewWillDisappear:(BOOL)animated
{
self.containerViewController.stillAnimatingTransition = YES;
[super viewWillDisappear:animated];
}
如果动画标志设置为 NO
,我的容器 View Controller 只允许执行后退和前进按钮,如下所示:
- (void)backButtonClicked
{
if (!self.isStillAnimatingTransition) {
// Do whatever.
}
}
- (void)forwardButtonClicked
{
if (!self.isStillAnimatingTransition) {
// Do whatever.
}
}
关于iphone - UINavigationController 过渡动画触发得太快,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19500025/