我不断收到一大堆约束警告,但它们似乎只有在通过标签栏控制器转换视图控制器时才会发生。
所以当我使用这段代码时,我没有错误:
let tbc = self.storyboard!.instantiateViewController(withIdentifier: "myViewController") as! myViewController
self.present(tbc, animated: false, completion: nil)
但是当我使用此代码进行转换时,出现了很多错误:
let tbc = self.storyboard!.instantiateViewController(withIdentifier: "MyTabController") as! UITabBarController
tbc.selectedIndex = 1
tbc.modalTransitionStyle = .coverVertical
self.present(tbc, animated: true, completion: nil)
这只是打印到控制台的错误的一个简单:
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2017-02-16 19:09:28.038332 ParseStarterProject-Swift[42916:640604] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x60800029e500 h=--& v=--& UIView:0x7fb66b551680.width == 142.8 (active)>",
"<NSAutoresizingMaskLayoutConstraint:0x60800029e4b0 h=--& v=--& UIView:0x7fb66b551680.height == 140 (active)>",
"<NSLayoutConstraint:0x60800029be90 UIImageView:0x7fb66b551820.width == UIImageView:0x7fb66b551820.height (active)>",
"<NSLayoutConstraint:0x60800029ba80 V:[UIImageView:0x7fb66b551820]-(50)-| (active, names: '|':UIView:0x7fb66b551680 )>",
"<NSLayoutConstraint:0x60800029c0c0 V:|-(0)-[UIImageView:0x7fb66b551820] (active, names: '|':UIView:0x7fb66b551680 )>",
"<NSLayoutConstraint:0x60800029c110 H:[UIImageView:0x7fb66b551820]-(15)-| (active, names: '|':UIView:0x7fb66b551680 )>",
"<NSLayoutConstraint:0x60800029c160 H:|-(15)-[UIImageView:0x7fb66b551820] (active, names: '|':UIView:0x7fb66b551680 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60800029be90 UIImageView:0x7fb66b551820.width == UIImageView:0x7fb66b551820.height (active)>
因此,我认为这可能与之相关的唯一约束如下图所示:
我已尝试过符号断点
UIViewAlertForUnsatisfiableConstraints
行动
expr -l objc++ -O -- [[UIWindow keyWindow] _autolayoutTrace]
并获取以下报告,但它不会识别任何约束或UI元素。
•UIWindow:0x7fb66b405490
| UITransitionView:0x7fb66b516fa0
| | UILayoutContainerView:0x7fb66b514e80
| | | UINavigationTransitionView:0x7fb66b613980
| | | | UIViewControllerWrapperView:0x7fb66b40e580
| | UITransitionView:0x7fb66b449f90
| UITransitionView:0x7fb66b45bd90
| | UILayoutContainerView:0x7fb66d831410
| | | UITransitionView:0x7fb66b605eb0
| | | | UIViewControllerWrapperView:0x7fb66b5567a0
| | | | | •UIView:0x7fb66b4300c0
| | | | | | *UICollectionView:0x7fb66b970400
| | | | | | | •ParseStarterProject_Swift.PackCollectionViewCell:0x7fb66d836fb0
| | | | | | | | +UIView:0x7fb66d8371d0
| | | | | | | | | *PFImageView:0x7fb66d837370
| | | | | | | | | *UILabel:0x7fb66d837560'This is a series of breat...'
| | | | | | | •ParseStarterProject_Swift.PackCollectionViewCell:0x7fb66b4651f0
| | | | | | | | +UIView:0x7fb66b465020
| | | | | | | | | *PFImageView:0x7fb66b465410
| | | | | | | | | *UILabel:0x7fb66b465600'Ever had trouble falling ...'
| | | | | | | •ParseStarterProject_Swift.PackCollectionViewCell:0x7fb66b560e60
| | | | | | | | +UIView:0x7fb66b561080
| | | | | | | | | *PFImageView:0x7fb66b561220
| | | | | | | | | *UILabel:0x7fb66b561410'This is a week long intro...'
| | | | | | | UIImageView:0x7fb66b4305c0
| | | | | | *_UILayoutGuide:0x7fb66b430260
| | | | | | *_UILayoutGuide:0x7fb66b430410
| | | UITabBar:0x7fb66b54c280
| | | | _UIBarBackground:0x7fb66d830680
| | | | | UIImageView:0x7fb66d830b20
| | | | | UIVisualEffectView:0x7fb66d830d00
| | | | | | _UIVisualEffectBackdropView:0x7fb66d8310a0
| | | | | | _UIVisualEffectFilterView:0x7fb66b40ddd0
| | | | | | _UIVisualEffectFilterView:0x7fb66b556940
| | | | UITabBarButton:0x7fb66d82f890
| | | | | UITabBarSwappableImageView:0x7fb66b43c280
| | | | | UITabBarButtonLabel:0x7fb66d82fb30'Menu'
| | | | UITabBarButton:0x7fb66b63e100
| | | | | UITabBarButtonLabel:0x7fb66b63e3a0
| | | | UITabBarButton:0x7fb66d830120
| | | | | UITabBarSwappableImageView:0x7fb66d828260
| | | | | UITabBarButtonLabel:0x7fb66d8303c0'Path'
| | | UIButton:0x7fb66b63e820
| | | | UIImageView:0x7fb66b4513c0
Legend:
* - is laid out with auto layout
+ - is laid out manually, but is represented in the layout engine because translatesAutoresizingMaskIntoConstraints = YES
• - layout engine host
(lldb)
我如何解决这个问题,或者至少如何具体查找报告的实例?它似乎没有任何效果,我已经在多种模拟器尺寸和设备上进行了测试。
答案 0 :(得分:0)
尝试使用DEBUG VIEW HIERARCHY解决它有关更多详细信息,请查看以下链接 - 它是解决这些类型的约束问题的最佳解决方案。
Unable to simultaneously satisfy constraints, will attempt to recover by breaking constraint
答案 1 :(得分:0)
让tbc = self.storyboard!.instantiateViewController(withIdentifier:“MyTabController”)为!的的UITabBarController 强>
它应该是您的班级名称而不是 UITabBarController