我有一个视图,我展示了两个不同的 uiwebviews(从本地 html 加载)。每次用户点击导航栏中的按钮时,我都会使用页面卷曲动画(向上卷曲和向下卷曲)从一个 web 视图切换到另一个。一切似乎都运行良好,但有时当用户点击该按钮时应用程序会冻结。在大多数情况下,当我重复点击按钮直到应用程序冻结时,应用程序会冻结,然后我暂停调试并得到以下信息:
self.navigationItem.titleView.userInteractionEnabled = NO; //Disable button interaction until animation is finished
if (self.isVisibleFrontView)
{
self.isVisibleFrontView = NO;
[UIView transitionWithView:self.view
duration:0.5
options:UIViewAnimationOptionTransitionCurlUp | UIViewAnimationOptionCurveEaseInOut
animations:^{
[[[self.view subviews] objectAtIndex:0] removeFromSuperview];
[self.view addSubview:self.patientViewReverse];
}
completion:^(BOOL finished){
self.navigationItem.titleView.userInteractionEnabled = YES;
}];
}
else
{
self.isVisibleFrontView = YES;
[UIView transitionWithView:self.view
duration:0.5
options:UIViewAnimationOptionTransitionCurlDown | UIViewAnimationOptionCurveEaseInOut
animations:^{
[[[self.view subviews] objectAtIndex:0] removeFromSuperview];
[self.view addSubview:self.patientView];
}
completion:^(BOOL finished){
self.navigationItem.titleView.userInteractionEnabled = YES;
}];
}
[self showNavigationBarButtons]; //change button image
}
我认为当 removeFromSuperview 时 webView 正在获取锁定,但在某些情况下从未释放它,导致主线程冻结。你怎么看?在不冻结应用程序的情况下实现这一目标的最佳方法是什么?
提前谢谢各位。