diff --git a/XXNibBridge/XXNibBridge.m b/XXNibBridge/XXNibBridge.m index f0856d7..8169db0 100644 --- a/XXNibBridge/XXNibBridge.m +++ b/XXNibBridge/XXNibBridge.m @@ -70,50 +70,50 @@ + (UIView *)instantiateRealViewFromPlaceholder:(UIView *)placeholderView { // Copy autolayout constrains. if (placeholderView.constraints.count > 0) { - - // We only need to copy "self" constraints (like width/height constraints) - // from placeholder to real view - for (NSLayoutConstraint *constraint in placeholderView.constraints) { - - NSLayoutConstraint* newConstraint; - - // "Height" or "Width" constraint - // "self" as its first item, no second item - if (!constraint.secondItem) { - newConstraint = - [NSLayoutConstraint constraintWithItem:realView - attribute:constraint.firstAttribute - relatedBy:constraint.relation - toItem:nil - attribute:constraint.secondAttribute - multiplier:constraint.multiplier - constant:constraint.constant]; - } - // "Aspect ratio" constraint - // "self" as its first AND second item - else if ([constraint.firstItem isEqual:constraint.secondItem]) { - newConstraint = - [NSLayoutConstraint constraintWithItem:realView - attribute:constraint.firstAttribute - relatedBy:constraint.relation - toItem:realView - attribute:constraint.secondAttribute - multiplier:constraint.multiplier - constant:constraint.constant]; - } - - // Copy properties to new constraint - if (newConstraint) { - newConstraint.shouldBeArchived = constraint.shouldBeArchived; - newConstraint.priority = constraint.priority; - if ([UIDevice currentDevice].systemVersion.floatValue >= 7.0f) { - newConstraint.identifier = constraint.identifier; + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + // We only need to copy "self" constraints (like width/height constraints) + // from placeholder to real view + for (NSLayoutConstraint *constraint in placeholderView.constraints) { + NSLayoutConstraint* newConstraint; + + // "Height" or "Width" constraint + // "self" as its first item, no second item + if (!constraint.secondItem) { + newConstraint = + [NSLayoutConstraint constraintWithItem:realView + attribute:constraint.firstAttribute + relatedBy:constraint.relation + toItem:nil + attribute:constraint.secondAttribute + multiplier:constraint.multiplier + constant:constraint.constant]; + } + // "Aspect ratio" constraint + // "self" as its first AND second item + else if ([constraint.firstItem isEqual:constraint.secondItem]) { + newConstraint = + [NSLayoutConstraint constraintWithItem:realView + attribute:constraint.firstAttribute + relatedBy:constraint.relation + toItem:realView + attribute:constraint.secondAttribute + multiplier:constraint.multiplier + constant:constraint.constant]; + } + + // Copy properties to new constraint + if (newConstraint) { + newConstraint.shouldBeArchived = constraint.shouldBeArchived; + newConstraint.priority = constraint.priority; + if ([UIDevice currentDevice].systemVersion.floatValue >= 7.0f) { + newConstraint.identifier = constraint.identifier; + } + [realView addConstraint:newConstraint]; } - [realView addConstraint:newConstraint]; } - } + }); } - + return realView; }