[英]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.