0
我正在编写自定义键盘,我想自定义高度.. Apple文档仅在Objective-C中给出该代码,是否有人知道如何使用Swift语言编写它?这是苹果公司代码:在swift中加载视图后自定义customKeyboard高度
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];
我试图把它写这样,但它不会做任何事情..:
override func viewDidAppear(animated:Bool) {
super.viewDidAppear(true)
let nib = UINib(nibName: "KeyboardView", bundle: nil)
let objects = nib.instantiateWithOwner(self, options: nil)
view = objects[0] as UIView;
let _viewHeight: CGFloat = 256
let const1 = NSLayoutConstraint(
item:self.view, attribute:.Height,
relatedBy:.Equal, toItem:nil,
attribute:.NotAnAttribute,multiplier:0, constant: _viewHeight)
view.addConstraint(const1)
}
请帮助我!
看看这个问题:https://stackoverflow.com/questions/24167909/ios-8-custom-keyboard-changing-the-height/25819565#25819565 – skyline75489