Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Swift更改iOS 8自定义键盘高度?_Ios_Objective C_Iphone_Swift_Keyboard - Fatal编程技术网

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

如何使用Swift更改iOS 8自定义键盘高度?,ios,objective-c,iphone,swift,keyboard,Ios,Objective C,Iphone,Swift,Keyboard,我正在使用Swift为iOS 8定制键盘。我对iOS开发非常陌生,我无法独自解决这个问题。在应用程序扩展在线编程文档中,苹果表示,用户可以在任何自定义键盘发布后更改其高度。他们在Objective-C中提供了一个示例,但我使用的是Swift,到目前为止,我似乎找不到该代码的Swift版本 有人能把这3行代码转换成Swift吗?或者告诉我一种改变键盘高度的方法 以下是带有代码的网页: 下面是代码行: CGFloat _expandedHeight = 500; NSLayoutConstrain

我正在使用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];
完全

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)

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

这是有效的代码

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)
}

这只是用错误的格式重复前面的答案。问题只针对第3行。@Mundi请将问题读为@Francis asked
有人能将这3行代码转换成Swift
而不是第3行吗?请给我看看faultsOK,谢谢你指出这一点。仍然没有必要重申显而易见的事情。我把你给我的代码放进了我键盘的.swift文件中,高度没有改变?你知道为什么吗?那将是一个不同的问题,对吗?在Objective-C中有效吗?我只试过Swift。但是我把它放在viewDidLoad方法中,我刚刚读到我显示把它放在viewDidAppear中,我会尝试一下,然后告诉你结果。但是我得到了这个:无法同时满足约束。可能下面列表中至少有一个约束是您不想要的。translatesAutoresizingMaskIntoConstraints)(“”,“”)我收到一个错误,错误是“找不到成员“高度”@ethang如果将inputview高度设置得较短,则会出现此问题。我现在也有同样的问题,但无论如何都找不到解决办法@是的,我终于找到了解决办法。您必须为约束设置优先级。就像这样:
height.priority=800
,轰,问题解决了!因此,将不会应用您的约束,并且键盘不会比本机键盘短?您可能需要查看此问题以了解更多详细信息:
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)
}