2017-01-23 29 views
0

У меня есть родительский VC, который загружает дочерний VC внутри него. Код в родительском VC выглядит следующим образом:Subview видимый, но рамка вне рамки супервизора

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

и код ребенок 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

ОК, получил его ...

я забывая ограничение высоты зрения ... Какой позор ...

[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

Такая же проблема ... Я не могу понять, что здесь происходит ... –