2016-10-27 9 views
0

私はストーリーボードにtitleViewを持っています。高さはタイトルで調整する必要があります。だから私は、このようなコードを記述します。アクティブ/非アクティブ制約時にNSLayoutConstraintの警告を修正する方法は?

- (void)adjustTitleView { 
    if (self.actionTitle.length > 0) { 
     self.titleViewHeight.active = NO; 
     self.titleLabelTop.active = YES; 
     self.titleLabelBottom.active = YES; 
    } else { 
     self.titleViewHeight.constant = 0.0; 
     self.tableHeight.active = YES; 
     self.titleLabelTop.active = NO; 
     self.titleLabelBottom.active = NO; 
    } 
} 

それは動作しますが、いくつかの警告があります

Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
     (1) look at each constraint and try to figure out which you don't expect; 
     (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x1482f0540 UIView:0x1482f0320.height == 0.5>", 
    "<NSLayoutConstraint:0x1482f0640 UIView:0x1482d0ad0.height == 0>", 
    "<NSLayoutConstraint:0x1482f06e0 UIView:0x1482f0320.top == UILabel:0x1482d0c40.bottom + 6.5>", 
    "<NSLayoutConstraint:0x1482f0780 UIView:0x1482d0ad0.bottom == UIView:0x1482f0320.bottom>", 
    "<NSLayoutConstraint:0x1482f08c0 UILabel:0x1482d0c40.top == UIView:0x1482d0ad0.top + 8>" 
) 

警告を修正する方法は?

答えて

0

試した後、私は非アクティブな制約、次にアクティブな制約を見つけ、次に他の制約を更新して警告を修正することができます。

- (void)adjustTitleView { 
    if (self.actionTitle.length > 0) { 
     [NSLayoutConstraint deactivateConstraints:@[self.titleViewHeight]]; 
     [NSLayoutConstraint activateConstraints:@[self.titleLabelTop, self.titleLabelBottom]]; 
    } else { 
     [NSLayoutConstraint deactivateConstraints:@[self.titleLabelTop, self.titleLabelBottom]]; 
     [NSLayoutConstraint activateConstraints:@[self.titleViewHeight]]; 
     self.titleViewHeight.constant = 0.0; 
    } 
} 
関連する問題