4
簡單,這是我的代碼NSGenericException加入一些限制時programatcially
func showMessageView(){
let leftConstraint = messageView.leftAnchor.constraintEqualToAnchor(self.view.leftAnchor)
let bottomConstraint = messageView.bottomAnchor.constraintGreaterThanOrEqualToAnchor(self.view.bottomAnchor)
let highConstratin = messageView.heightAnchor.constraintEqualToConstant(44.0)
let widthConstraint = messageView.widthAnchor.constraintGreaterThanOrEqualToAnchor(self.view.widthAnchor)
NSLayoutConstraint.activateConstraints([leftConstraint, bottomConstraint, highConstratin, widthConstraint])
self.view.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(messageView)
}
和我收到此異常:
終止應用程序由於未捕獲的異常「NSGenericException」,原因:「無法激活約束條目< UIView:0x7fe62e00be70; frame =(0 0; 240 128); autoresize = RM + BM;層= < CALayer:0x7fe62e06c8f0 >>和< UITableView:0x7fe62c80be00; frame =(0 0; 375 667); clipsToBounds = YES; autoresize = W + H; gestureRecognizers = < NSArray:0x7fe62b6a54f0>;層= < CALayer:0x7fe62b53aba0>; contentOffset:{0,-64}; contentSize:{375,658}>,因爲它們沒有共同的祖先。約束是否引用不同視圖層次中的項目?這是非法的。「