我正在使用 Swift 为 iOS 8 制作自定义键盘。我对 iOS 开发非常陌生,我无法自己解决这个问题。苹果在在线应用程序扩展编程文档中表示,您可以在任何自定义键盘启动后更改其高度。他们提供了 Objective-C 的示例,但我使用的是 Swift,到目前为止,我似乎找不到代码的 Swift 版本。
有人可以将这 3 行代码转换为 Swift 或告诉我一种改变键盘高度的方法吗?
这是代码行:
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)
}
关于ios - 如何使用 Swift 更改 iOS 8 自定义键盘高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25484272/