uinavigationcontroller

uinavigationcontroller

本文介绍了UINavigationController过渡动画触发得太快的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的词典应用程序中使用自定义的容器视图控制器。基本上,容器视图控制器在顶部包含一个自定义导航栏(一个 UINavigationBar - 只是一个 UIView 带后退和前进 UIButtons UISearchBar ,书签 UIButton 在右边),底部有一个标签栏控制器。

I'm using a custom-made container view controller in my dictionary app. Basically, the container view controller contains a custom navigation bar on top (NOT a UINavigationBar--just a UIView with back and forward UIButtons, a UISearchBar, and a bookmark UIButton at the right), and a tab bar controller at the bottom.

我的问题是:我使用后退和前进按钮推送和其中一个选项卡中的弹出视图控制器( UINavigationController ),以便用户可以浏览字典浏览历史记录。但是,如果我按后退或前进按钮的速度太快,我会在日志窗格中显示此消息,而某些屏幕根本不显示:

My problem is this: I use the back and forward buttons to push and pop view controllers in one of the tabs (a UINavigationController) so the user can navigate through the dictionary browsing history. However, if I press the back or forward buttons too fast, I get this message in the log pane and some of the screens don't appear at all:

环顾四周StackOverflow,我明白这是因为单击后退或前进按钮太快会调用活动选项卡中 UINavigatonController 的push / pop方法,但它不会让动画完成。

Looking around StackOverflow, I understood that this is because clicking on the back or forward buttons too fast calls the push/pop methods of the UINavigatonController in the active tab, but it does not let the animation finish. https://stackoverflow.com/a/17440074/855680

在没有动画的情况下推送或弹出视图控制器可以解决问题,但我确实希望保留动画。我该如何处理这个问题?我查看了 UINavigationController 类引用,看看是否有任何委托方法或属性表明它在动画中间,但似乎没有。

Pushing or popping view controllers without the animations solves the problem, but I do want to keep the animations. How can I approach this problem? I looked at the UINavigationController class reference to see if there are any delegate methods or properties that indicate that it's in the middle of an animation, but there doesn't seem to be any.

推荐答案

修正了我自己。解决方案是在容器视图控制器中创建一个属性,指示 UINavigationController 转换动画是否仍在发生:

Fixed it myself. The solution was to create a property in my container view controller which indicates whether the UINavigationController transition animations are still happening:

@property (nonatomic, getter = isStillAnimatingTransition) BOOL stillAnimatingTransition;

现在,对于所有 UIViewController 类,我进入 UINavigationController ,我将此标志设置为 YES 在每个视图控制器的 viewWillDisappear viewDidAppear 方法中,如下所示:

Now, for all the UIViewController classes that I push into the UINavigationController, I set this flag to YES or NO in each of the view controllers' viewWillDisappear and viewDidAppear methods, like this:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    self.containerViewController.stillAnimatingTransition = NO;
}

- (void)viewWillDisappear:(BOOL)animated
{
    self.containerViewController.stillAnimatingTransition = YES;
    [super viewWillDisappear:animated];
}

我的容器视图控制器只允许执行后退和前进按钮如果动画标志设置为,则如下所示:

And my container view controller only ever allows the execution of the back and forward buttons if the animation flag is set to NO, like this:

- (void)backButtonClicked
{
    if (!self.isStillAnimatingTransition) {
        // Do whatever.
    }
}

- (void)forwardButtonClicked
{
    if (!self.isStillAnimatingTransition) {
        // Do whatever.
    }
}

这篇关于UINavigationController过渡动画触发得太快的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 03:27