[英]Auto Layout Programmatically with Scroll View Error
我试图在ViewController的pages-scrollView内添加一个视图,并且遇到很多自动布局问题(所有这些代码都是程序化的,非Storyboard的)。
第一组约束正常工作,但是第二组约束( sv
和firstView
)导致以下错误: libc++abi.dylib: terminating with uncaught exception of type NSException
对此代码的任何帮助将不胜感激,代码如下:
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .whiteColor()
sv.backgroundColor = .redColor()
view.addSubview(sv)
sv.translatesAutoresizingMaskIntoConstraints = false
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[sv]|", options: .DirectionLeadingToTrailing, metrics: nil, views: ["sv": sv]))
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[sv]|", options: .DirectionLeadingToTrailing, metrics: nil, views: ["sv": sv]))
sv.pagingEnabled = true
let firstView = UIView()
firstView.backgroundColor = .greenColor()
sv.addSubview(firstView)
firstView.translatesAutoresizingMaskIntoConstraints = false
sv.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[f]|", options: .DirectionLeadingToTrailing, metrics: nil, views: ["fv": firstView]))
sv.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[fv]|", options: .DirectionLeadingToTrailing, metrics: nil, views: ["fv": firstView]))
}
正如@dan指出的那样,字符串中的视觉格式有错别字。 如果有人碰巧遇到类似问题,我将保留此帖子。 外卖:
使用自动布局以terminating with uncaught exception of type NSException
可能是由可视字符串中的错字引起的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.