2017-01-23 4 views
0

하위 VC를로드하는 상위 VC가 있습니다.서브 뷰는 표시되지만 슈퍼 뷰 프레임 외부의 프레임

self.draggerViewController = [[DraggerViewController alloc] initWithSuperView:self.view]; 

그리고 VC는 다음과 같다 아이의 코드 : 다음과 같이 부모 VC에서 코드가이 코드

- (instancetype)initWithSuperView:(UIView*)superView { 
    self = [super init]; 

    if (self) { 
     self.superView = superView; 

     [self.view setTranslatesAutoresizingMaskIntoConstraints:NO]; 
     [superView addSubview:self.view]; 

     [superView addConstraint:[NSLayoutConstraint constraintWithItem:superView attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeading multiplier:1 constant:0]]; 

     [superView addConstraint:[NSLayoutConstraint constraintWithItem:superView attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTrailing multiplier:1 constant:0]]; 

     self.constraintDraggerAttributeBottom = [NSLayoutConstraint constraintWithItem:superView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1 constant:0]; 
     [superView addConstraint:self.constraintDraggerAttributeBottom]; 
    } 

    return self; 
} 

을, 하위 뷰는 부모 뷰에 표시하고 제약 조건이 올바르게 적용됩니다 그래서 그것은 선행 및 후행이 0 인 상위 뷰의 맨 아래에 배치됩니다. 그러나 뷰의 실제 프레임은 상위 뷰 외부에 있습니다.

즉, 부모보기 하단에서 하위보기를 볼 수 있지만이 하위보기의 프레임은 frame = (0 -315; 768 35)입니다.

'clipToBounds'를 'YES'로 설정하면보기가 실제 프레임에 배치되지만 제약 조건이 올바르게 적용되지 않습니다.

제약 조건을 사용하여 원하는 위치에서이 VC를 부모 VC의 뷰 내부에 배치하려면 어떻게해야합니까?

감사합니다.

답변

1

OK, 그것을 가지고 ...

내가보기의 높이 제한 ... 어떤 수치를 잊고 있었다 ...

[superView addConstraint:[NSLayoutConstraint constraintWithItem:superView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeHeight multiplier:1 constant:0]]; 

다들 감사 해요!

0

이 시도 :

superView.insertSubview(self.view, at: self. superView.subviews.count) 
+0

동일한 문제 ... 여기 무슨 일이 일어나고 있는지 이해할 수 없습니다 ... –