iOS Contstraints导致SIGABRT错误

时间:2017-09-09 05:10:07

标签: ios swift autolayout constraints

我使用可视语言制作约束,但每当我尝试添加它们时都会导致错误。

class TimerViewController : UIViewController{
    let timer = TimerView()
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = .white
        self.view.addSubview(timer)
        self.createContraints()
    }

    func createContraints(){
        self.timer.translatesAutoresizingMaskIntoConstraints = false
        let horizontalConstraints = 
NSLayoutConstraint.constraints(withVisualFormat: "H:|[timer]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["timer" : timer])
        let verticleContraints = 
NSLayoutConstraint.constraints(withVisualFormat: "V:|==[timer]==|", options: NSLayoutFormatOptions(), metrics: nil, views: ["timer" : timer])
        self.view.addConstraints(horizontalConstraints)
        self.view.addConstraints(verticleContraints)
    }
}

1 个答案:

答案 0 :(得分:2)

Xcode为您提供错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse constraint format: 
Expected a view 
V:|==[timer]==| 
   ^'

所以删除==它会起作用。