Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS8 Swift自定义键盘按钮UIimage大小问题_Swift_Ios8_Custom Keyboard - Fatal编程技术网

iOS8 Swift自定义键盘按钮UIimage大小问题

iOS8 Swift自定义键盘按钮UIimage大小问题,swift,ios8,custom-keyboard,Swift,Ios8,Custom Keyboard,我正在尝试用swifts创建一个iOS8自定义键盘。 到目前为止,我的应用程序运行良好,只是我的UIImage按钮的大小有问题。 我使用以下方法将键盘大小设置为100像素: override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) view.addConstraint(NSLayoutConstraint(item: self.view, attribute: .Height, relatedB

我正在尝试用swifts创建一个iOS8自定义键盘。 到目前为止,我的应用程序运行良好,只是我的UIImage按钮的大小有问题。 我使用以下方法将键盘大小设置为100像素:

override func viewDidAppear(animated: Bool) {
  super.viewDidAppear(animated)
  view.addConstraint(NSLayoutConstraint(item: self.view, attribute: .Height, relatedBy:.Equal, toItem:self.view,
  attribute:.Height, multiplier:0.0, constant: 100))
然后我按以下方式添加关键按钮:

let image = UIImage(named: "key1.jpg")
nextKeyboardButton = UIButton.buttonWithType(.System) as UIButton
nextKeyboardButton.setBackgroundImage(image, forState: UIControlState.Normal)
// initialize the button
nextKeyboardButton.sizeToFit()
self.nextKeyboardButton.addTarget(self, action: "advanceToNextInputMode", forControlEvents: .TouchUpInside)
self.view.addSubview(self.nextKeyboardButton)
var nextKeyboardButtonLeftSideConstraint = NSLayoutConstraint(item: self.nextKeyboardButton, attribute: .Left, relatedBy: .Equal, toItem: self.view, attribute: .Left, multiplier: 1.0, constant: 0.0)
var nextKeyboardButtonBottomConstraint = NSLayoutConstraint(item: self.nextKeyboardButton, attribute: .Bottom, relatedBy: .Equal, toItem: self.view, attribute: .Bottom, multiplier: 1.0, constant: 0.0)
self.view.addConstraints([nextKeyboardButtonLeftSideConstraint, nextKeyboardButtonBottomConstraint])
我的key1.jpg精确到100像素高。它确实适合我的键盘区域大小Height=100,但两者都太大了。因此,似乎每个像素的实际视网膜分辨率为2个像素或更多。而且宽度是非常大的。我用一个400像素宽的按键进行了测试,屏幕上刚好有一半。我还尝试了一个.png文件,同样的结果。一定有一些一般设置错误,但我真的不知道是什么

检查错误输出时,我收到以下消息:

Unable to simultaneously satisfy constraints.
    ... 
(
    "<NSLayoutConstraint:0x1700913f0 'UIView-Encapsulated-Layout-Height' V:[UIInputView:0x13f5091e0(216)]>",
    "<NSLayoutConstraint:0x170091d00 V:[UIInputView:0x13f5091e0(100)]>"
)
我确实把最高点设为100,但216的最高点从何而来

这是它的样子

资料来源:

应该是这样的


问题记录在日志中:

Unable to simultaneously satisfy constraints.
    ... 
(
    "<NSLayoutConstraint:0x1700913f0 'UIView-Encapsulated-Layout-Height' V:[UIInputView:0x13f5091e0(216)]>",
    "<NSLayoutConstraint:0x170091d00 V:[UIInputView:0x13f5091e0(100)]>"
)

您可能正在使用故事板中的Autolayout或代码中的任何其他位置设置高度。只需将其删除或更改为较低优先级,并将其设置为100px。

您可以添加屏幕截图吗?它现在看起来怎么样?它应该看起来怎么样?你能在日志中看到关于自动布局的任何错误吗?哦,是的,我忘了检查错误日志,很好!我在问题中添加了错误。我也添加了图片