带有Xcode 8 beta的自定义键盘故事板 [英] Custom Keyboard Storyboard with Xcode 8 beta

查看:117
本文介绍了带有Xcode 8 beta的自定义键盘故事板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Xcode 8 beta 6的情节提要中设计自定义键盘时遇到一些问题.
由于某些原因,当我在iOS 10设备上启动键盘时,结果如下:

这就是我在情节提要中进行设计的方式,顶视图:


底视图:

I'm having some problems designing my custom keyboard from the storyboard in Xcode 8 beta 6.
For some reason when I launch the keyboard on a iOS 10 device this is the result:

This is how i design it in the Storyboard, Top View:


Bottom View:



所以它只显示底部视图的高度.
iOS 9没有这个问题.



So it displays only the height of the bottom view.
I don't have this problem with iOS 9.
Any ideas on what is going wrong?

更新:
这就是在iOS 9中加载键盘的方式:

UPDATE:
this it's how the keyboard gets loaded in iOS 9:

更新2:
甚至以这种方式在 viewDidLoad()中以编程方式创建视图也不起作用:

UPDATE 2:
Even creating the view programmatically this way in viewDidLoad() doesn't work:

self.view.backgroundColor = UIColor.orange

let bottomView = UIView()

bottomView.backgroundColor = UIColor.blue

self.view.addSubview(bottomView)

bottomView.translatesAutoresizingMaskIntoConstraints = false

let trailing = bottomView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor)
let leading = bottomView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor)
let bottom = bottomView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor, constant: -50)
let top = bottomView.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 0)

NSLayoutConstraint.activate([trailing, leading, bottom, top])

我写了苹果的错误报告.
希望从他们那里得到消息

I wrote to apple bug report.
Hope to get news from them

推荐答案

我遇到了同样的问题.我假设您没有在绿色块上设置高度,因为您希望它填满键盘的剩余空间.如果您希望键盘的高度保持恒定,则只需在绿色块上设置高度限制就可以了,但是由于屏幕尺寸和方向的原因,您可能并不想为所有内容都设置一个高度.

I had this same issue. I assume you don't have a height set on the green block because you want it to fill up the remaining space of the keyboard. If you want the keyboard to be a CONSTANT height you can simply set a height constraint on the green block and you're done, but because of screen sizes and orientations you probably don't want one height for everything.

在iOS 9中,自定义键盘的默认大小与系统键盘相同.因此,如果您在iOS 9中运行此程序,则绿色块会根据这些尺寸填充剩余的空间.在iOS 10中,由于某种原因,没有默认的高度,并且由于您的绿色块没有高度限制,因此它认为高度为零.

In iOS 9 the default size for a custom keyboard was the same as the system keyboard. So if you run this in iOS 9, the green block fills up the remaining space based on those dimensions. In iOS 10 for some reason there is no default height, and because your green block has no height constraint it thinks the height is zero.

要修复此问题,您需要为键盘设置高度.这是我编写的用于处理它的代码(到目前为止非常好).将此放置在ViewDidLoad之前的keyboardviewcontroller类中,您应该会很好:

To fix it you need to set a height for your keyboard. This is the code I wrote to handle it (and so far so good). Place this in the keyboardviewcontroller class before the ViewDidLoad and you should be good to go:

//***************************

//create constraint variable before function
var constraint = NSLayoutConstraint()

//function to set height
func setKeyboardHeight () {
    let screenSize = UIScreen.mainScreen().bounds.size
    let screenH = screenSize.height;

    self.view.removeConstraint(constraint)

    //you can set the values below as needed for your keyboard
    if screenH >= 768 {
        //for iPad landscape or portrait
        self.constraint = NSLayoutConstraint(item: self.view, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 0.0, constant: 300.0)
        self.view.addConstraint(self.constraint)

    } else if screenH >= 414 {
        //for iPhone portrait AND iPhone Plus landscape or portrait
        self.constraint = NSLayoutConstraint(item: self.view, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 0.0, constant: 220.0)
        self.view.addConstraint(self.constraint)

    } else {
        //for iPhone landscape
        self.constraint = NSLayoutConstraint(item: self.view, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 0.0, constant: 140.0)
        self.view.addConstraint(self.constraint)
    }
}

//sets height when keyboard loads
override func updateViewConstraints() {
    super.updateViewConstraints()
    // Add custom view sizing constraints here
    setKeyboardHeight()
}

//sets or changes height when device rotates
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
    setKeyboardHeight()
}

//***************************

这篇关于带有Xcode 8 beta的自定义键盘故事板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆