答案 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;
}