Я добавляю подтаблицы в Панель навигации, проблема заключается в том, что им не удалось добавить ограничения к нему .IM получая крах как этотКак программно добавить ограничения на uinavigationbar подвид
истекающий приложение из-за неперехваченного исключением «NSGenericException ', причина:' Невозможно активировать ограничение с элементами; значение: 0.000000> и>, потому что у них нет общего предка. Имеются ли ссылочные позиции ограничений в разных иерархиях представлений? Это незаконно.
Код, используемый ниже
//create a slider and add it to the view
let slider = UISlider()
self.navigationController?.navigationBar.addSubview(slider)
//pin the slider 20 points from the left edge of the the superview
//from the left edge of the slider to the left edge of the superview
//superview X coord is at 0 therefore 0 + 20 = 20 position
let horizonalContraints = NSLayoutConstraint(item: slider, attribute:
.LeadingMargin, relatedBy: .Equal, toItem: view,
attribute: .LeadingMargin, multiplier: 1.0,
constant: 20)
//pin the slider 20 points from the right edge of the super view
//negative because we want to pin -20 points from the end of the superview.
//ex. if with of super view is 300, 300-20 = 280 position
let horizonal2Contraints = NSLayoutConstraint(item: slider, attribute:
.TrailingMargin, relatedBy: .Equal, toItem: view,
attribute: .TrailingMargin, multiplier: 1.0, constant: -20)
//pin 100 points from the top of the super
let pinTop = NSLayoutConstraint(item: slider, attribute: .Top, relatedBy: .Equal,
toItem: view, attribute: .Top, multiplier: 1.0, constant: 100)
//when using autolayout we an a view, MUST ALWAYS SET setTranslatesAutoresizingMaskIntoConstraints
//to false.
slider.translatesAutoresizingMaskIntoConstraints = false
slider.backgroundColor = UIColor.redColor()
//IOS 8
//activate the constrains.
//we pass an array of all the contraints
NSLayoutConstraint.activateConstraints([horizonalContraints, horizonal2Contraints,pinTop])
Приведенный выше код работает отлично, если я использую линию view.addSubview(slider)
вместо
self.navigationController?.navigationBar.addSubview(slider)
Но идея заключается в том, чтобы добавить ограничения на подвид на Панель навигации . Любые мысли приветствуются