如何在ios中显示UIView

时间:2016-05-06 10:46:58

标签: ios objective-c uiview

我已经将我的观点视为某种逻辑:

[self.view addConstraint:[NSLayoutConstraint constraintWithItem:_parentOfPhotoview
                                                              attribute:NSLayoutAttributeHeight
                                                              relatedBy:NSLayoutRelationEqual
                                                                 toItem:nil
                                                              attribute:NSLayoutAttributeNotAnAttribute
                                                             multiplier:1.0
                                                               constant:0]];

但是我再次需要让它在某一点上可见,所以我尝试了这个:

[self.view addConstraint:[NSLayoutConstraint constraintWithItem:_parentOfPhotoview
                                                              attribute:NSLayoutAttributeHeight
                                                              relatedBy:NSLayoutRelationEqual
                                                                 toItem:nil
                                                              attribute:NSLayoutAttributeNotAnAttribute
                                                             multiplier:1.0
                                                               constant:48]];

48将是实际高度。但它不可见。 我在这里做错了什么?

1 个答案:

答案 0 :(得分:0)

解决方案之一是将高度约束声明为IBOutlet并将其连接到IB:

@property (nonatomic, weak) IBOutlet NSLayoutConstraint *heightConstraint;

以这种方式改变它的高度:

- (void)changeHeight:(CGFloat )height {
  self.heightConstraint.constant = height;
  [UIView animateWithDuration:0.3 animations:^{
      [self.view layoutIfNeeded];
}];
}