gpt4 book ai didi

ios - 快速加载 View 后自定义自定义键盘高度

转载 作者:行者123 更新时间:2023-11-29 02:23:05 26 4
gpt4 key购买 nike

我正在编写一个自定义键盘,我想自定义高度..Apple 文档仅在 Objective-C 中提供该代码,有谁知道如何用 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];

我试着这样写,但它什么也没做..:

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)

}

请帮帮我!

最佳答案

您有一个multiplier:0,它应该是multiplier:1.0

您还可以将 self.viewview =objects[0] 混合作为 UIView。您应该向主 self.view 添加一个约束,即 = self.inputView 并在其上添加自定义 View 。

let customView = objects[0] as UIView
customView.setTranslatesAutoresizingMaskIntoConstraints(false)
self.view.addSubView(customView)

//layout
let left = NSLayoutConstraint(item: customView, attribute: .Left, relatedBy: .Equal, toItem: view, attribute: .Left, multiplier: 1.0, constant: 0.0)
let top = NSLayoutConstraint(item: customView, attribute: .Top, relatedBy: .Equal, toItem: view, attribute: .Top, multiplier: 1.0, constant: 0.0)
let right = NSLayoutConstraint(item: customView, attribute: .Right, relatedBy: .Equal, toItem: view, attribute: .Right, multiplier: 1.0, constant: 0.0)
let bottom = NSLayoutConstraint(item: customView, attribute: .Bottom, relatedBy: .Equal, toItem: view, attribute: .Bottom, multiplier: 1.0, constant: 0.0)
self.view.addConstraints([left, top, right, bottom])

let const1 = NSLayoutConstraint(
item:self.view, attribute:.Height,
relatedBy:.Equal, toItem:nil,
attribute:.NotAnAttribute,multiplier:1.0, constant: _viewHeight)
self.view.addConstraint(const1)

关于ios - 快速加载 View 后自定义自定义键盘高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27888653/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com