встраивание панели навигации/вкладки нарушает ограничения нормально функционального представления

у меня простой

UIViewController, который обычно работает:

  1. вид.backgroundColor
  2. UITextView
  3. UIView (как прокладка между низом и текстовым представлением)
  4. ограничения для закрепления textview в представлении, которое, в свою очередь, закреплено в нижней планировке
  5. нажатие на текстовое представление загружает клавиатуру, и представление разделителя соответственно расширяется, чтобы клавиатура не перекрывала мой текстовый вид

...
//var memoArea = UITextView(frame: CGRectMake(20, 291, 275, 225))
memoArea.addConstraint(NSLayoutConstraint(item: memoArea, attribute: .Width, relatedBy: .Equal,
   toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 275.0))

memoArea.addConstraint(NSLayoutConstraint(item: memoArea, attribute: .Height, relatedBy: .Equal,
    toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 225.0))

self.view.addConstraint(NSLayoutConstraint(item: memoArea, attribute: .Leading, relatedBy: .Equal,
    toItem: self.view, attribute: .Leading, multiplier: 1.0, constant: 20.0))

// var spacer:UIView = UIView(frame: CGRectMake(84, 518, 160, 6))
spacer.addConstraint(NSLayoutConstraint(item: spacer, attribute: .Width, relatedBy: .Equal,
   toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 160.0))

spacer.addConstraint(NSLayoutConstraint(item: spacer, attribute: .Height, relatedBy: .Equal,
    toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 6.0))

self.view.addConstraint(NSLayoutConstraint(item: spacer, attribute: .Leading, relatedBy: .Equal,
    toItem: self.view, attribute: .Leading, multiplier: 1.0, constant: 84.0))

view.setTranslatesAutoresizingMaskIntoConstraints(false)
spacer.setTranslatesAutoresizingMaskIntoConstraints(false)
memoArea.setTranslatesAutoresizingMaskIntoConstraints(false)
...

...
func updateBottomLayoutConstraintWithNotification(notification: NSNotification) {
let userInfo = notification.userInfo!
let animationDuration = (userInfo[UIKeyboardAnimationDurationUserInfoKey] as NSNumber).doubleValue
let keyboardEndFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as NSValue).CGRectValue()
let convertedKeyboardEndFrame = view.convertRect(keyboardEndFrame, fromView: view.window)
let rawAnimationCurve = (notification.userInfo![UIKeyboardAnimationCurveUserInfoKey] as NSNumber).unsignedIntValue << 16
let animationCurve = UIViewAnimationOptions.init(UInt(rawAnimationCurve))

let frame = self.tabBarController?.tabBar.frame
let height = frame?.size.height
spacerToBottom.constant = CGRectGetMaxY(view.bounds) - CGRectGetMinY(convertedKeyboardEndFrame) - height! - 5

UIView.animateWithDuration(animationDuration, delay: 0.0, options: .BeginFromCurrentState | animationCurve, animations: {
self.view.layoutIfNeeded()
}, completion: nil)
...

Но после добавления либо панели вкладок, либо панели навигации в представление с нормально работающими ограничениями,

ломаются 3 вещи:

  1. фон больше не отображается, давая черный фон
  2. текстовое представление не регистрирует нажатия, т.е. клавиатура не загружается
  3. представление игнорирует нижний макет. он просто сдвигает мои объекты настолько высоко, насколько позволяют их ограничения .Top. ограничения между textview и uiview по-прежнему соблюдаются.

person stanley    schedule 01.12.2014    source источник


Ответы (1)


комментирование view.setTranslatesAutoresizingMaskIntoConstraints(false) избавило от всех ошибок.

person stanley    schedule 02.12.2014