2014-09-17 2 views
0

Я создал пользовательскую клавиатуру с xib-файлом. Он отлично работает и показывается, как я хочу, но при отладке клавиатуры я получаю много предупреждений. Я создал все ограничения в xib и добавил его в качестве подзаголовка для моего представления.Swift - Пользовательская высота клавиатуры

var nib = UINib(nibName: "Keyboard", bundle: nil) 
let objects = nib.instantiateWithOwner(self, options: nil) 
mainView = objects.first as UIView 
view.addSubview(mainView) 

Я делаю это в видеDidLoad() - метод. В viewDidAppear() Я называю это, чтобы получить мой рост:

let heightConstraint = NSLayoutConstraint(item: self.view, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 0.0, constant: 180.0) 
     view.addConstraint(heightConstraint) 

mainView.frame = view.bounds 

Но теперь я получаю это предупреждение:

2014-09-17 12:21:21.689 Hodor[6629:1086407] Unable to simultaneously satisfy constraints. 
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x178087e40 'UIView-Encapsulated-Layout-Height' V:[UIInputView:0x15e607830(264)]>", 
    "<NSLayoutConstraint:0x1780882f0 V:[UIInputView:0x15e607830(180)]>" 
) 

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x178087e40 'UIView-Encapsulated-Layout-Height' V:[UIInputView:0x15e607830(264)]> 

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. 
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful. 
2014-09-17 12:21:21.693 Hodor[6629:1086407] Unable to simultaneously satisfy constraints. 
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x178087e40 'UIView-Encapsulated-Layout-Height' V:[UIInputView:0x15e607830(264)]>", 
    "<NSLayoutConstraint:0x1780882f0 V:[UIInputView:0x15e607830(180)]>" 
) 

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x178087e40 'UIView-Encapsulated-Layout-Height' V:[UIInputView:0x15e607830(264)]> 

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. 
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful. 
2014-09-17 12:21:21.697 Hodor[6629:1086407] Unable to simultaneously satisfy constraints. 
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x178087e40 'UIView-Encapsulated-Layout-Height' V:[UIInputView:0x15e607830(264)]>", 
    "<NSLayoutConstraint:0x1780882f0 V:[UIInputView:0x15e607830(180)]>" 
) 

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x178087e40 'UIView-Encapsulated-Layout-Height' V:[UIInputView:0x15e607830(264)]> 

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. 
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful. 

Что это значит? Из текста предупреждений кажется что-то с ограничением по высоте ...

+0

Можете ли вы опубликовать скриншот своих ограничений и макета из XIB? Похоже, одно ограничение придало клавиатуре явную высоту 180 точек. Но тогда отдельное ограничение (либо от расстояния до вершины + расстояние до дна, и т. Д.) Того, что кажется содержательным супервидом, пытается установить его на 264. Кто-то, у кого больше опыта, анализирующий эти ошибки, может сузить его , –

+0

Итак, вот макет: https://cloudup.com/crqoINgTXqg Ограничения, которые я сделал: - следующая кнопка находится в левом нижнем углу, а размер зафиксирован на 60x60 - левая кнопка находится в правой верхний угол имеет фиксированную ширину 60 и ту же высоту, что и кнопка вниз - кнопка вниз находится в правом нижнем углу, имеет фиксированную ширину 60 и имеет ту же высоту, что и левая кнопка - большая кнопка в середине, если зафиксировано на левом, правом, верхнем и кнопочном кадре с расстоянием 0 Вид сам по себе составляет 320x180 в xib, а клавиатура должна быть 180 в высоту ... – Ben

+0

Пожалуйста, посмотрите на [принятый ответ] 1] из @ skyline75489. Оно работает! [1]: http://stackoverflow.com/questions/24167909/ios-8-custom-keyboard-changing-the-height/25819565#comment40988935_25819565 – lifjoy

ответ

2

Попробуйте

view.setTranslatesAutoresizingMaskIntoConstraints (ложь) view.addConstraint (NSLayoutConstraint ( пункт: MainView, атрибут: .left, relatedBy: .Equal, toItem: вид, атрибут: NSLayoutAttribute.Left, умножитель: 0,6, постоянный: 0))

view.addConstraint(NSLayoutConstraint(
     item:mainView, attribute:.Right, 
     relatedBy:.Equal, toItem:view, 
     attribute:.RightMargin,multiplier:0.6, constant: 0)) 

    view.addConstraint(NSLayoutConstraint(
     item:mainView, attribute:.Width, 
     relatedBy:.Equal, toItem:view, 
     attribute: .Width,multiplier:0.6, constant: 0)) 

    view.addConstraint(NSLayoutConstraint(
     item:mainView, attribute:.Height, 
     relatedBy:.Equal, toItem:view, 
     attribute:.Height,multiplier:0.6, constant: 0)) 
+0

Если я это сделаю, вид из ниба слишком мал или слишком велик, независимо от того, установлен ли его до или после meinView.frame = view.bounds. И есть также предупреждение. Не так много, как раньше, но это одно предупреждение, которое говорит то же, что и выше. – Ben

+0

@BenjaminHerzog для mainView добавляет те же ограничения и удаляет mainView.frame = view.bounds – Ramesh

+0

Я написал это прямо после heightconstraint в viewDidAppear(). Основной вид, который является моим nib с собственными ограничениями через построитель интерфейсов, слишком велик. Я писал: mainView.frame = view.frame view.setTranslatesAutoresizingMaskIntoConstraints (ложь) mainView.setTranslatesAutoresizingMaskIntoConstraints (ложь) – Ben

1

Есть некоторые конфликты с ограничениями. Autoresize противоречит ограничениям, которые вы применили.

+0

Но какие ограничения? В тексте нет имен моих торговых точек. Я написал свои ограничения в комментарии по вопросу, не могли бы вы взглянуть, пожалуйста? :) – Ben

+0

Всякий раз, когда вы добавляете ограничение для высоты, вы должны установить ограничения на его вертикальную (x) и горизонтальную (y) позицию. Установка этих ограничений разрешит этот конфликт с помощью авторазрешения. –

+0

Я установил горизонтальное и вертикальное положение с помощью ограничений верхнего правого угла. Таким образом, левая кнопка управления, например, находится в верхнем правом углу .. всегда .. И затем я устанавливаю ее размер. Я не понимаю. Клавиатура выглядит хорошо, как и должно. Почему существуют предупреждения? – Ben

Смежные вопросы