Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

property IBOutlet NSLayoutConstraint nil #24

Open
SANZOGENJO opened this issue Jul 13, 2016 · 1 comment
Open

property IBOutlet NSLayoutConstraint nil #24

SANZOGENJO opened this issue Jul 13, 2016 · 1 comment

Comments

@SANZOGENJO
Copy link

since version 2.3 ,if some of one view's subviews is Custom,the property IBOutlet NSLayoutConstraint width or height will be nil,if i change the property to strong, it will not work set
.constant

@erlangzhang
Copy link

if (placeholderView.constraints.count > 0) {
  for (NSLayoutConstraint* constraint in placeholderView.constraints) {
    if ([UIDevice currentDevice].systemVersion.floatValue < 10) {
      if (constraint.firstItem == placeholderView) {
        [constraint setValue:realView forKey:@"firstItem"];
      }
      if (constraint.secondItem == placeholderView) {
        [constraint setValue:realView forKey:@"secondItem"];
      }
    } else {
      Ivar referenceItem =
      class_getInstanceVariable(NSLayoutAnchor.class, "_referenceItem");
      id firstAnchorItem = object_getIvar(
                                          [constraint valueForKey:@"firstAnchor"], referenceItem);
      if (firstAnchorItem == placeholderView) {
        object_setIvar([constraint valueForKey:@"firstAnchor"], referenceItem,
                       realView);
      }
      if ([constraint valueForKey:@"secondAnchor"] != nil) {
        id secondAnchorItem = object_getIvar(
                                             [constraint valueForKey:@"secondAnchor"], referenceItem);
        if (secondAnchorItem == placeholderView) {
          object_setIvar([constraint valueForKey:@"secondAnchor"],
                         referenceItem, realView);
        }
      }
    }
  }
  [realView addConstraints:placeholderView.constraints];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants