亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

iOS 8自定義鍵盤:更改高度

iOS 8自定義鍵盤:更改高度

iOS
皈依舞 2019-10-16 12:45:25
我試圖在iOS 8中創建一個自定義鍵盤來替換普通鍵盤。我確實進行了搜索,無法確定是否可以創建比現有iOS鍵盤高的鍵盤。我替換了UIInputView,但無法更改對我可用的高度。
查看完整描述

3 回答

?
精慕HU

TA貢獻1845條經驗 獲得超8個贊

最近,Apple更新了其App擴展編程指南,以更改自定義鍵盤擴展的高度:


CGFloat _expandedHeight = 500;


NSLayoutConstraint *_heightConstraint = [NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0 constant: _expandedHeight];


[self.view addConstraint: _heightConstraint];


查看完整回答
反對 回復 2019-10-16
?
守著一只汪

TA貢獻1872條經驗 獲得超4個贊

這是我發現導致高度正確更新的最小解決方案。似乎有兩個關鍵組成部分:


translatesAutoresizingMaskIntoConstraints設置為的視圖false需要添加到視圖層次結構中。

高度約束的添加時間不得早于viewWillAppear。

我仍然Unable to simultaneously satisfy constraints在日志中看到錯誤,但是無論如何看來工作正常。我還仍然看到一個跳躍,在該跳躍中,高度最初設置為默認值,然后再跳躍到設置值。我還沒有找到解決這些問題的方法。


import UIKit


class KeyboardViewController: UIInputViewController {


    var heightConstraint: NSLayoutConstraint!


    override func viewWillAppear(animated: Bool) {

        super.viewWillAppear(animated)

        self.inputView.addConstraint(self.heightConstraint)

    }


    override func viewDidLoad() {

        super.viewDidLoad()


        let dummyView = UILabel(frame:CGRectZero)

        dummyView.setTranslatesAutoresizingMaskIntoConstraints(false)

        self.view.addSubview(dummyView);


        let height : CGFloat = 400


        self.heightConstraint = NSLayoutConstraint( item:self.inputView, attribute:.Height, relatedBy:.Equal, toItem:nil, attribute:.NotAnAttribute, multiplier:0.0, constant:height)

    }

}

Swift 4更新:


import UIKit


class KeyboardViewController: UIInputViewController

{

    private weak var _heightConstraint: NSLayoutConstraint?


    override func viewWillAppear(_ animated: Bool)

    {

        super.viewWillAppear(animated)


        guard nil == _heightConstraint else { return }


        // We must add a subview with an `instrinsicContentSize` that uses autolayout to force the height constraint to be recognized.

        //

        let emptyView = UILabel(frame: .zero)

        emptyView.translatesAutoresizingMaskIntoConstraints = false

        view.addSubview(emptyView);


        let heightConstraint = NSLayoutConstraint(item: view,

                                                  attribute: .height,

                                                  relatedBy: .equal,

                                                  toItem: nil,

                                                  attribute: .notAnAttribute,

                                                  multiplier: 0.0,

                                                  constant: 240)

        heightConstraint.priority = .required - 1

        view.addConstraint(heightConstraint)

        _heightConstraint = heightConstraint

    }

}


查看完整回答
反對 回復 2019-10-16
  • 3 回答
  • 0 關注
  • 980 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號