gpt4 book ai didi

ios App - 同时在多个 segue 上崩溃(在一个正在动画时转到其他 segue)

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:06:02 25 4
gpt4 key购买 nike

当一个 segue(如 perforrmsegue)的动画正在进行时,如果其他 segue 发生(如果用户当时按下其他按钮)则应用程序崩溃。

解决了 UINavigationController 上的 pop 和 pushViewController 的相同问题 here .

我们是否也可以对 segue 使用相同的 trik 还是有其他解决方案。

崩溃后我得到以下堆栈。 (异常发生在 [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:]

如果此异常(exception)是出于任何其他原因,请提及,因为我不确定转场。

最佳答案

这个解决方案对我有用,我认为在程序中添加它是一般做法。

1)

首先将 BOOL 属性添加到应用的 appDelegate 的 .h 文件中

@property (nonatomic) BOOL animatingViewControllerTransition;

同时实现UINavigationControllerDelegate:

@interface Your_AppDelegate : UIResponder <UIApplicationDelegate, UINavigationControllerDelegate>

application:didFinishLaunchingWithOptions: 中将 Your_AppDelegate 设置为 UINavigationController 的委托(delegate):

((UINavigationController *)self.window.rootViewController).delegate = self;

2)

现在在您的 appDelegate 的 .m 文件中添加此 UINavigationControllerDelegate 方法:

- (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的时候添加下面的代码

- (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 崩溃问题的人有所帮助。

关于ios App - 同时在多个 segue 上崩溃(在一个正在动画时转到其他 segue),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22421845/

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