Autolayout在iOS 8上运行良好,在iOS 7上崩溃

时间:2015-06-16 12:11:05

标签: ios ios7 ios8 autolayout

我遇到一个问题,即自动布局的屏幕在iOS 8上运行良好 - 但在iOS 7上崩溃了。 所有子视图都在XIB中配置。

错误消息是:

Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to install constraint on view.
Does the constraint reference something from outside the subtree of the view?  That's illegal. 
constraint:<NSLayoutConstraint:0x7ef80720 V:[UIImageView:0x7ef7fb40]-(0)-[UILabel:0x7ef802f0]> view:<UIView: 0x7ef7f1e0; frame = (0 0; 768 275); autoresize = RM+BM; layer = <CALayer: 0x7ef7f240>>'

这是堆栈跟踪:

(
0   CoreFoundation                      0x0588a1e4 __exceptionPreprocess + 180
1   libobjc.A.dylib                     0x0563d8e5 objc_exception_throw + 44
2   CoreFoundation                      0x05889fbb +[NSException raise:format:] + 139
3   Foundation                          0x0284d55f -[NSLayoutConstraint _addToEngine:integralizationAdjustment:mutuallyExclusiveConstraints:] + 197
4   Foundation                          0x028509ad -[NSLayoutConstraint _addToEngine:] + 56
5   UIKit                               0x0460c974 __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke_2 + 515
6   Foundation                          0x029c768c -[NSISEngine withBehaviors:performModifications:] + 107
7   Foundation                          0x028573c5 -[NSISEngine withAutomaticOptimizationDisabled:] + 48
8   UIKit                               0x0460ce40 -[UIView(AdditionalLayoutSupport) _withAutomaticEngineOptimizationDisabledIfEngineExists:] + 63
9   UIKit                               0x0460c754 __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke + 476
10  UIKit                               0x0460ce48 -[UIView(AdditionalLayoutSupport) _withAutomaticEngineOptimizationDisabledIfEngineExists:] + 71
11  UIKit                               0x0460c54f -[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:] + 223
12  UIKit                               0x0460c46b -[UIView(AdditionalLayoutSupport) _parentalLayoutEngineDidChangeTo:] + 55
13  UIKit                               0x0460c850 __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke_2 + 223
14  Foundation                          0x029c768c -[NSISEngine withBehaviors:performModifications:] + 107
15  Foundation                          0x028573c5 -[NSISEngine withAutomaticOptimizationDisabled:] + 48
16  UIKit                               0x0460ce40 -[UIView(AdditionalLayoutSupport) _withAutomaticEngineOptimizationDisabledIfEngineExists:] + 63
17  UIKit                               0x0460c754 __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke + 476
18  UIKit                               0x0460ce48 -[UIView(AdditionalLayoutSupport) _withAutomaticEngineOptimizationDisabledIfEngineExists:] + 71
19  UIKit                               0x0460c54f -[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:] + 223
20  UIKit                               0x0460c46b -[UIView(AdditionalLayoutSupport) _parentalLayoutEngineDidChangeTo:] + 55
21  UIKit                               0x0460c850 __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke_2 + 223
22  Foundation                          0x029c768c -[NSISEngine withBehaviors:performModifications:] + 107
23  Foundation                          0x028573c5 -[NSISEngine withAutomaticOptimizationDisabled:] + 48
24  UIKit                               0x0460ce40 -[UIView(AdditionalLayoutSupport) _withAutomaticEngineOptimizationDisabledIfEngineExists:] + 63
25  UIKit                               0x0460c754 __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke + 476
26  UIKit                               0x0460ce48 -[UIView(AdditionalLayoutSupport) _withAutomaticEngineOptimizationDisabledIfEngineExists:] + 71
27  UIKit                               0x0460c54f -[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:] + 223
28  UIKit                               0x0460c46b -[UIView(AdditionalLayoutSupport) _parentalLayoutEngineDidChangeTo:] + 55
29  UIKit                               0x03fd0948 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 119
30  Foundation                          0x029c768c -[NSISEngine withBehaviors:performModifications:] + 107
31  Foundation                          0x028573c5 -[NSISEngine withAutomaticOptimizationDisabled:] + 48
32  UIKit                               0x03fd0830 -[UIView(Hierarchy) _postMovedFromSuperview:] + 313
33  UIKit                               0x03fdbdd4 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1875
34  UIKit                               0x03fcedba -[UIView(Hierarchy) addSubview:] + 56
35  UIKit                               0x03f66645 -[_UIParallaxDimmingView didMoveToWindow] + 129
36  UIKit                               0x03fd9478 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 1642
37  UIKit                               0x03fd9109 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 763
38  UIKit                               0x03fd096f __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 158
39  Foundation                          0x029c768c -[NSISEngine withBehaviors:performModifications:] + 107
40  Foundation                          0x028573c5 -[NSISEngine withAutomaticOptimizationDisabled:] + 48
41  UIKit                               0x03fd0830 -[UIView(Hierarchy) _postMovedFromSuperview:] + 313
42  UIKit                               0x03fdbdd4 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1875
43  UIKit                               0x03fcedba -[UIView(Hierarchy) addSubview:] + 56
44  UIKit                               0x03f630f2 __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke + 2001
45  UIKit                               0x03fd581f +[UIView(Animation) performWithoutAnimation:] + 82
46  UIKit                               0x03f624f6 -[_UINavigationParallaxTransition animateTransition:] + 1155
47  UIKit                               0x040a93ae -[UINavigationController _startCustomTransition:] + 3446
48  UIKit                               0x040b58f7 -[UINavigationController _startDeferredTransitionIfNeeded:] + 688
49  UIKit                               0x040b64e9 -[UINavigationController __viewWillLayoutSubviews] + 57
50  UIKit                               0x041f70d1 -[UILayoutContainerView layoutSubviews] + 213
51  UIKit                               0x03fde964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
52  libobjc.A.dylib                     0x0564f82b -[NSObject performSelector:withObject:] + 70
53  QuartzCore                          0x03dac45a -[CALayer layoutSublayers] + 148
54  QuartzCore                          0x03da0244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
55  QuartzCore                          0x03da00b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
56  QuartzCore                          0x03d067fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
57  QuartzCore                          0x03d07b85 _ZN2CA11Transaction6commitEv + 393
58  QuartzCore                          0x03dc55b0 +[CATransaction flush] + 52
59  UIKit                               0x03f6d9bb _UIApplicationHandleEventQueue + 13095
60  CoreFoundation                      0x0581377f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
61  CoreFoundation                      0x0581310b __CFRunLoopDoSources0 + 235
62  CoreFoundation                      0x058301ae __CFRunLoopRun + 910
63  CoreFoundation                      0x0582f9d3 CFRunLoopRunSpecific + 467
64  CoreFoundation                      0x0582f7eb CFRunLoopRunInMode + 123
65  GraphicsServices                    0x06b4f5ee GSEventRunModal + 192
66  GraphicsServices                    0x06b4f42b GSEventRun + 104
67  UIKit                               0x03f6ff9b UIApplicationMain + 1225
68  Pageonce                            0x000db639 main + 73
69  libdyld.dylib                       0x064fe6d9 start + 1

问题是什么?

1 个答案:

答案 0 :(得分:0)

原来这两行造成了崩溃:

self.ninjaStarImage.layer.removeFromSuperlayer()
self.view.layer.addSublayer(self.ninjaStarImage.layer)

将它们移至viewDidLayoutSubviews解决了问题