ios – translatesAutoresizingMaskIntoConstraints和IB

在UIView.h中,您可以阅读以下内容:

/* by default, the autoresizing mask on a view gives rise to constraints 
   that fully determine the view's position.  Any constraints you set on 
   the view are likely to conflict with autoresizing constraints, 
   so you must turn off this property first. IB will turn it off for you.
 */
- (BOOL)translatesAutoresizingMaskIntoConstraints NS_AVAILABLE_IOS(6_0); // Default YES

因此,这意味着当您从xib创建UIView时,translatesAutoresizingMaskIntoConstraints应设置为NO.

但是,当我使用[[UINib nibWithNibName:nibName bundle:[NSBundle mainBundle]] instantiateWithOwner:self options:nil]创建一个xib视图时,translatesAutoresizingMaskIntoConstraints设置为YES.

知道为什么吗?

最佳答案 事实证明,这是一个已经在Apple的bug记者中提交的错误.它应该在将来的版本中修复.

点赞