我有以下代码,它在我的 iPhone 5 和所有 iPhone 模拟器上运行良好,但在我的 iPhone 4 上崩溃了。我在最后一行将 UITransitionContextToViewKey 传递到我的转换上下文时得到 EXC_BAD_ACCESS。
我进行了清晰的分析和构建,UITransitionContextFromViewKey 和 UITransitionContextToViewKey 也发生了同样的情况。
我的 iPhone 4 在 iOS 7.1.2 上,我的部署目标是 7.0,目标构建基础 SDK 8.0。
有人知道怎么办吗?谢谢。
- (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 及更高版本,但 viewControllerForKey 方法在 iOS 7 中受支持。对代码稍作更改即可获得 iOS 7 中的 View :
UIView *destinationView = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey].view;
关于ios - EXC_BAD_ACCESS 从 iPhone 4 上的过渡上下文中检索 View 时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26415070/