将一个xib粘贴到另一个xib上

时间:2015-07-11 06:58:16

标签: ios objective-c autolayout xib

我想将蓝色视图粘贴到黄色视图上。

screenshot

然而,无论我如何改变蓝色的自动布局,都会有冲突。

按中间的按钮,然后显示视图。

Xcode project

1 个答案:

答案 0 :(得分:0)

将此行添加到您的UIViewController + testAlert.m

文件中
containerFrame.size.width = view.frame.size.width;

之后

containerFrame.size.height = view.frame.size.height;

所以showAlertViewB函数的代码就像

if (show) {
    NSArray* nibViews = [[NSBundle mainBundle] loadNibNamed:@"AlertViewB" owner:self options:nil];
    alertViewB = (AlertViewB*)[nibViews objectAtIndex:0];
//        [alertViewB removeConstraint:alertViewB.containerHeightConstraint];
//        NSLayoutConstraint *newContainerHeightConstraint = [NSLayoutConstraint constraintWithItem:alertViewB attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeHeight multiplier:1.0 constant:view.frame.size.height];
//        [alertViewB addConstraint:newContainerHeightConstraint];
    CGRect containerFrame = alertViewB.container.frame;
    containerFrame.size.height = view.frame.size.height;
    containerFrame.size.width = view.frame.size.width;
    [alertViewB.container setFrame:containerFrame];

    [alertViewB setTranslatesAutoresizingMaskIntoConstraints:YES];
    alertViewB.delegate =self;
    [alertViewB showWithView:view];
} else {
    [alertViewB removeFromSuperview];
    alertViewB = nil;
}