0

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ピクセルです。私のキーボード領域のサイズ (高さ = 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 はどこから来るのでしょうか?

これがどのように見えるかです

大きなボタンへ
(出典:modelautos24.de

そして、それはそのように見えるはずです

正しいボタン

4

1 に答える 1

0

問題はログに次のように書かれています。

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

ストーリーボード (またはコード内の他の場所) で Autolayout を使用して高さを設定している可能性があります。それを削除する (または優先度を下げる) だけで、100px に設定する必要があります。

于 2014-12-17T10:18:32.100 に答える