gpt4 book ai didi

iphone - Swift - 自定义键盘高度

转载 作者:行者123 更新时间:2023-11-28 11:22:46 24 4
gpt4 key购买 nike

我用 xib 文件创建了一个自定义键盘。它可以完美地工作并按我的意愿显示,但是在调试键盘时我收到很多警告。我在 xib 中创建了所有约束并将其作为 subview 添加到我的 View 中。

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

我在 viewDidLoad() 方法中执行此操作。在 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.

这是什么意思?从警告的文本​​来看,它似乎是有高度限制的……

最佳答案

试试这个

view.setTranslatesAutoresizingMaskIntoConstraints(假)view.addConstraint(NSLayoutConstraint( 项目:mainView,属性:.Left, relatedBy:.Equal, toItem:view, 属性: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))

关于iphone - Swift - 自定义键盘高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25888140/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com