问题描述
当一个segue(如perforrmsegue)的动画正在进行时,如果发生其他segue(如果用户当时按下其他按钮),则应用程序崩溃.
While animation of one segue(like perforrmsegue) is going, if other segue occures (if user press other button at that time) then application is crashing.
UINavigationController 上 pop 和 pushViewController 的相同问题已解决这里.
The same problem for the pop and pushViewController on UINavigationController is solved here.
我们是否也可以使用相同的 trik 进行 segue 或有其他解决方案.
Can we use same trik for segue also or there is other solution.
崩溃后我得到以下堆栈.([NSException initWithCoder:] 处的异常).
I get the following stack after crash. (Exeption at [NSException initWithCoder:]).
0 CoreFoundation 0x2f9fbf4b __exceptionPreprocess
1 libobjc.A.dylib 0x39d8b6af objc_exception_throw
2 CoreFoundation 0x2f9fbe8d -[NSException initWithCoder:]
3 UIKit 0x3217a48f -[UIView(Internal) _addSubview:positioned:relativeTo:]
4 UIKit 0x3217a417 -[UIView(Hierarchy) addSubview:]
5 UIKit 0x32342b71 __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke
6 UIKit 0x321806e5 +[UIView(Animation) performWithoutAnimation:]
如果此例外是出于任何其他原因,请提及这一点,因为我不确定转场.
If this exeption is for any other reason then please mention that because I an not sure about the segue.
推荐答案
这个解决方案对我有用,我认为在程序中添加它是一般做法.
This solution worked for me and I think it's general practice to add this in the program.
1)
首先将 BOOL
属性添加到您应用的 appDelegate 的 .h 文件中
First add BOOL
property to your .h file of your app's appDelegate
@property (nonatomic) BOOL animatingViewControllerTransition;
同时实现UINavigationControllerDelegate
:
@interface Your_AppDelegate : UIResponder <UIApplicationDelegate, UINavigationControllerDelegate>
在你的 appDelegate:
Set Your_AppDelegate as UINavigationController's delegate in application:didFinishLaunchingWithOptions:
of your appDelegate:
((UINavigationController *)self.window.rootViewController).delegate = self;
2)
现在在 appDelegate 的 .m 文件中添加这个 UINavigationControllerDelegate 方法:
Now Add this UINavigationControllerDelegate method in .m file of your appDelegate:
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
// Push/pop operation is allowed now.
((Your_AppDelegate *)[UIApplication sharedApplication].delegate).animatingViewControllerTransition = NO;
}
3)
最后在segueing时添加以下代码
Finally Add the following code whenever you are segueing
- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
{
// Don't allow to segue if already one of the view controllers is being animated
BOOL viewControllerIsTransitioning = ((Your_AppDelegate *)[UIApplication sharedApplication].delegate).animatingViewControllerTransition;
if (viewControllerIsTransitioning)
{
return NO;
}
return YES;
}
希望这对遇到 segue 崩溃问题的人有所帮助.
Hope this will help to one having segue crash problem.
这篇关于ios App - 同时在多个 segue 上崩溃(在一个正在制作动画时转到另一个 segue)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!