Swift default AlertViewController breaking constraints

前端 未结 9 685
野趣味
野趣味 2020-11-27 14:25

I am trying to use a default AlertViewController with style .actionSheet. For some reason, the alert causes a constraint error. As long as

9条回答
  •  粉色の甜心
    2020-11-27 15:03

    The solution for Objective-C:

    1. Subclass your own Alert Controller from UIAlertController
    2. Define prune-function like in previous reply

      @implementation TemplateAlertController
      
      -(void) viewDidLoad {
      
          [super viewDidLoad];
          [self mPruneNegativeWithConstraints];
      }
      
      -(void) mPruneNegativeWithConstraints {
      
          for (UIView* iSubview in [self.view subviews]) {
              for (NSLayoutConstraint* iConstraint in [iSubview constraints]) {
                  if ([iConstraint.debugDescription containsString:@"width == - 16"]) {
                      [iSubview removeConstraint:iConstraint];
                  }
              }
          }
      }
      
      @end
      

提交回复
热议问题