EXC_BAD_ACCESS从iPhone 4上的转换上下文检索视图时



我有以下代码,它在我的iPhone 5和所有iPhone模拟器上都能完美工作,但在我的iPhone4上崩溃了。我在最后一行得到EXC_BAD_ACCESS,在那里我将UITransitionContextToViewKey传递给我的转换上下文。

我有一个干净的分析和构建,UITransitionContextFromViewKey和UITransitionTextToViewKey也发生了同样的情况。

我的iPhone 4在iOS 7.1.2上,我的部署目标是7.0,目标是构建基础SDK 8.0。

有人知道在这里该做什么吗?thx。

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
    // get transition parameters from context
    UIView *containerView = transitionContext.containerView;
    UIViewController *destinationViewController =
    [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    if ([destinationViewController.title isEqualToString:@"ListController"]) {
        // get source and destination views
        UIView *sourceViewSnapshot = [self.view snapshotViewAfterScreenUpdates:YES];
        UIView *destinationView = [transitionContext viewForKey:UITransitionContextToViewKey]; // EXC_BAD_ACCESS
// ...
}

viewForKey方法是iOS 8及更高版本,但在iOS 7中支持viewControllerForKey方法。对代码的一个小更改可以在iOS 7:中查看

   UIView *destinationView = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey].view;

来自文档:

UITransitionContext到ViewKey

适用于iOS 8.0及更高版本

你不能在iOS 7 上运行该代码

如果您想保持与此版本的系统的兼容性,此时您可能需要添加运行时系统版本检查并扩展到iOS 7兼容的代码

最新更新