gpt4 book ai didi

ios - popViewController Animated : from alertView:didDismissWithButtonIndex: 的断断续续的动画

转载 作者:行者123 更新时间:2023-11-29 00:54:07 25 4
gpt4 key购买 nike

当它在 UIalertView 委托(delegate)方法 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 年以来,该代码在应用程序中就没有被修改过,并且最近开始表现得很奇怪。

最佳答案

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

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

对我来说这个工作没问题!希望这对你有帮助

关于ios - popViewController Animated : from alertView:didDismissWithButtonIndex: 的断断续续的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37795148/

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