2015-07-11 49 views

回答

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; 
} 
+0

谢谢!它确实有用! –

+0

请问为什么这个工作? 即使我将ViewController.m行46〜49和UIViewController + testAlert.m行41注释掉了。 –

+0

我不熟悉代码中的设置框架如何与自动布局进行交互。 –