런타임에 화면의 하위보기에 제약 조건을 추가하려고합니다. 이것은 충돌을 일으키는 것입니다. 다음은 내 코드입니다 :iOS Autolayout이 문제를 제한합니다. | App crashing
2017년 10월 23일 : 10 : 39 :
for var i in 0 ..< 5{ let aController = storyboard.instantiateViewController(withIdentifier: "design") let itemView = aController.view //itemView!.frame.origin.x = CGFloat(i) * itemView!.frame.width itemView!.translatesAutoresizingMaskIntoConstraints = false itemView!.addConstraint(NSLayoutConstraint(item: scrollView, attribute: .trailing, relatedBy: .equal, toItem: itemView!, attribute: .trailing, multiplier: 1, constant: 20)) itemView!.addConstraint(NSLayoutConstraint(item: scrollView, attribute: .leading, relatedBy: .equal, toItem: itemView!, attribute: .leading, multiplier: 1, constant: 0)) itemView!.addConstraint(NSLayoutConstraint(item: scrollView, attribute: .top, relatedBy: .equal, toItem: itemView!, attribute: .top, multiplier: 1, constant: 20)) itemView!.addConstraint(NSLayoutConstraint(item: scrollView, attribute: .bottom, relatedBy: .equal, toItem: itemView!, attribute: .bottom, multiplier: 1, constant: 20)) scrollView.addSubview(itemView!) }
내가 점점 오전 오류 것은 아래로이다 37.087674 + 0530 RollerCoasterPotential [998 : 22689] [LayoutConstraints] 뷰 계층 구조는 제약 조건에 대해 준비되어 있지 않습니다.
뷰에 추가 할 때 제약 조건의 항목은 해당 뷰 (또는 뷰 자체)의 자손이어야합니다. 뷰 계층 구조가 어셈블되기 전에 제약 조건을 해결해야하는 경우 충돌이 발생합니다. 휴식을 위해 - [UIView (UIConstraintBasedLayout) _viewHierarchyUnpreparedForConstraint :] 디버깅 할 수 있습니다.
2017년 10월 23일 10 : 39 : 37.087924 + RollerCoasterPotential 0530 : IN [998 22,689] * 어설 션 오류 - [UIView의 _layoutEngine_didAddLayoutConstraint : roundingAdjustment : mutuallyExclusiveConstraints :] /BuildRoot/라이브러리/캐시/COM. apple.xbs/소스/UIKit_Sim/UIKit-3688.4/NSLayoutConstraint_UIKitAdditions.m : 734 2017년 10월 23일 10 : 39 : 37.177966 + 0530 RollerCoasterPotential [998 : 22689] * 의한 캐치되지 않는 예외 'NSInternalInconsistencyException'에 앱 종료 , 이유 : '보기 계층을 제약 조건으로 준비하지 않고 레이아웃을 설정할 수 없습니다.'
ViewController에서 scrollView를 정의하고 추가하는 방법은 무엇입니까? –
ScrollView가 Interface Builder (동적으로 추가되지 않음)를 통해 추가되었습니다. – TechBee
먼저 scrollviewAutoresizingMaskIntoConstraints를 false로 설정해야한다고 생각하지 않습니다. itemView마다 false로 설정해야합니다. 둘째, Autolayout을 사용하는 경우 itemview의 프레임 원점을 설정할 필요가 없습니다. 셋째, itemview에 대한 자동 레이아웃 제약 조건 (위치 및 크기를 만족시키고 후행 제약 조건을 만족시키기 위해)을 작성하여 scrollview에 추가해야합니다. 다른 방법으로하지 마십시오. –