繁体   English   中英

如何使用Swift更改iOS 8自定义键盘高度?

[英]How to change iOS 8 custom keyboard height with Swift?

我正在使用Swift为iOS 8创建自定义键盘。 我对iOS开发非常陌生,无法独自解决此问题。 Apple在在线的App Extension编程文档中说,您可以在启动任何自定义键盘后更改其高度。 他们在Objective-C中提供了一个示例,但是我正在使用Swift,到目前为止,我似乎找不到该代码的Swift版本。

有人可以将三行代码转换为Swift或向我展示一种改变键盘高度的方法吗?

这是带有代码的网页: https : //developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/ExtensibilityPG/Keyboard.html

这是代码行:

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];

我将提供的代码添加到viewDidAppear方法中,并调整了键盘的大小。

这是起作用的代码。

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)
    let expandedHeight:CGFloat = 500
    let heightConstraint = NSLayoutConstraint(item:self.view,
        attribute: .Height,
        relatedBy: .Equal,
        toItem: nil,
        attribute: .NotAnAttribute,
        multiplier: 0.0,
        constant: expandedHeight)
    self.view.addConstraint(heightConstraint)
}
let heightConstraint = NSLayoutConstraint(item: view, 
                                     attribute: .Height, 
                                     relatedBy: .Equal, 
                                        toItem: nil, 
                                     attribute: .NotAnAttribute, 
                                    multiplier: 0.0, 
                                      constant: expandedHeight)

完全,

let expandedHeight:CGFloat = 500
        let heightConstraint = NSLayoutConstraint(item:self.view,
            attribute: .Height,
            relatedBy: .Equal,
            toItem: nil,
            attribute: .NotAnAttribute,
            multiplier: 0.0,
            constant: expandedHeight)
            self.view.addConstraint(heightConstraint)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM