【问题标题】:Choppy animation of popViewControllerAnimated: from alertView:didDismissWithButtonIndex:popViewController Animated 的断断续续的动画:来自警报 View:didDismissWithButtonIndex:
【发布时间】:2016-06-13 16:49:15
【问题描述】:

当在 UIalertView 委托方法 alertView:didDismissWithButtonIndex: 中完成时,我遇到了方法 popViewControllerAnimated: 中的动画问题。它不稳定且快速(使用 Xcode 7.3.1)。谁能明白为什么?

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if (buttonIndex != alertView.cancelButtonIndex)
    {
        // animation of popViewControllerAnimated: is not working correctly
        [self.navigationController popViewControllerAnimated:YES];
    }
}

奇怪的是这段代码没有问题:

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if (buttonIndex != alertView.cancelButtonIndex)
    {
        // code is running om main thread
        if ([[NSThread currentThread]isMainThread])  {
            // still - by using GCD and go to main thread, the animation works!!
            dispatch_async(dispatch_get_main_queue(), ^{
                [self.navigationController popViewControllerAnimated:YES];
            });
        }
    }
}

还有这个:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

    if(buttonIndex != alertView.cancelButtonIndex)
    {
        // no problem with animation when done in alertView:clickedButtonAtIndex:
        [self.navigationController popViewControllerAnimated:YES];
    }
}

我知道UIAlertView 已经被弃用了一段时间,是不是因为这个?自 2012 年以来,此代码在应用程序中一直未触及,最近开始表现得很奇怪。

【问题讨论】:

    标签: ios grand-central-dispatch uialertview popviewcontrolleranimated


    【解决方案1】:

    您可以尝试使用willDismissWithButtonIndex 而不是didDismissWithButtonIndex

    - (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
    {
        if (buttonIndex != alertView.cancelButtonIndex)
        {
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
    

    对我来说这项工作还可以!希望对你有所帮助

    【讨论】:

    • 是的,谢谢它的工作原理:) 以及clickedButtonAtIndex:,正如我在问题中所写的那样。但是我仍然对didDismissWithButtonIndex:....的问题感到困惑。
    猜你喜欢
    • 2011-02-27
    • 1970-01-01
    • 2016-12-24
    • 2011-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-23
    • 2012-02-08
    相关资源
    最近更新 更多