[英]Auto Layout Programmatically with Scroll View Error
I am trying to have add a view inside a paging-scrollView inside of a ViewController, and I am having a lot of Auto Layout problems (all of this code is programatic, non-Storyboard). 我试图在ViewController的pages-scrollView内添加一个视图,并且遇到很多自动布局问题(所有这些代码都是程序化的,非Storyboard的)。
The first set of constraints work properly, but the second set ( sv
and firstView
) cause the following error: libc++abi.dylib: terminating with uncaught exception of type NSException
第一组约束正常工作,但是第二组约束(
sv
和firstView
)导致以下错误: libc++abi.dylib: terminating with uncaught exception of type NSException
Any help on this issue would be greatly appreciated, code below: 对此代码的任何帮助将不胜感激,代码如下:
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]))
}
As @dan pointed out, there is a typo in the string in the visual format. 正如@dan指出的那样,字符串中的视觉格式有错别字。 I'll leave this post up in case anyone happens to run into a similar issue.
如果有人碰巧遇到类似问题,我将保留此帖子。 The take-away:
外卖:
terminating with uncaught exception of type NSException
with Auto Layout might be caused by typos in the visual strings. 使用自动布局以
terminating with uncaught exception of type NSException
可能是由可视字符串中的错字引起的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.