在委托方法popViewControllerAnimated:
中完成时,我遇到了方法中的动画问题。它断断续续且速度很快(使用 Xcode 7.3.1)。谁能明白为什么?UIalertView
alertView:didDismissWithButtonIndex:
- (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 年以来,此代码在应用程序中一直未触及,最近开始表现得很奇怪。