2013-06-24 3 views
0

나는 프로그래밍 방식으로 UIView의 내부에 세 가지보기에 다음과 같은 제약 조건을 설정하고있다 :왜 이러한 제약 조건이 작동하지 않습니까?

UIView *view1 = ((UIViewController *)[self.viewControllers objectAtIndex:0]).view; 
UIView *view2 = ((UIViewController *)[self.viewControllers objectAtIndex:1]).view; 
UIView *view3 = ((UIViewController *)[self.viewControllers objectAtIndex:2]).view; 

NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(view1, view2, view3); 
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[view1(==320)]-0-[view2(==320)]-0-[view3(==320)]|" options:0 metrics:0 views:viewsDictionary]]; 

내 의도는 각보기에 높이 앉아, 320 ~ 넓은 것을 하나 - 다른 간극없이, 왼쪽에 대한 최대보기 하나 포함 UIView의 가장자리.

컴파일 할 때 그러나 뷰에 탑 하나 서로 배치하고 난 콘솔에서 다음을 얻을 :

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) 
(
    "<NSLayoutConstraint:0x211811c0 H:|-(0)-[UIView:0xc683790] (Names: '|':UIView:0xc683320)>", 
    "<NSAutoresizingMaskLayoutConstraint:0x21179820 h=-&- v=-&- UIView:0xc683790.midX == UIView:0xc683320.midX - 340>", 
    "<NSLayoutConstraint:0x211793d0 H:[UIView:0xc6a50c0]-(0)-| (Names: '|':UIView:0xc683320)>", 
    "<NSLayoutConstraint:0x21179390 H:[UIView:0xc6a50c0(320)]>", 
    "<NSLayoutConstraint:0x21179350 H:[UIView:0xc6a05f0]-(0)-[UIView:0xc6a50c0]>", 
    "<NSLayoutConstraint:0x211563d0 H:[UIView:0xc6a05f0(320)]>", 
    "<NSLayoutConstraint:0x21156390 H:[UIView:0xc683790]-(0)-[UIView:0xc6a05f0]>" 
) 

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x21179350 H:[UIView:0xc6a05f0]-(0)-[UIView:0xc6a50c0]> 

답변

0

는 모두를 위해

[view setTranslatesAutoresizingMaskIntoConstraints:NO]; 

설정을 시도하여 일반적으로 이러한 종류의 문제를 해결하기에 충분합니다.

관련 문제