I'm making a custom keyboard in iOS8 and I'd like to be able to increase and decrease the size of the keyboard. I know from the iOS documentation that you can increase the height of the keyboard after it has loaded using this code:
我正在iOS8中制作一个自定义键盘,我希望能够增加和减少键盘的大小。我从iOS文档中了解到,在使用了这个代码后,您可以增加键盘的高度:
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)
}
But the problem with this code is, if the expandedHeight is 500 to begin with, if at a later time in the running of the keyboard I want to increase that to 600 for example, nothing happens and sometimes the keyboard crashes.
但这段代码的问题是,如果展开高度是500,如果在以后的运行中我想把它增加到600,比如,什么都没发生,有时键盘会崩溃。
Is there any other way to increase and decrease the height of the keyboard that works when I increase the height?
有没有其他的方法来增加和减少键盘的高度当我增加高度的时候?
Also I've been using a swipe up gesture to increase the height of the keyboard and a swipe down gesture to decrease it. Can you swipe up and down without lifting your finger and have it register as an up and a down gesture?
我还使用了向上滑动的手势来增加键盘的高度,向下滑动的手势来减少键盘的高度。你可以上下滑动而不需要举起你的手指,让它注册为一个向上和向下的手势吗?
1 个解决方案
#1
1
Please look at the accepted answer from @skyline75489-- which is the only solution that worked for me.
请查看@skyline75489的公认答案——这是唯一对我有效的解决方案。
Like you, my keyboard has a gesture recognizer that toggles the keyboard height between short/tall values. My gesture recognizer calls a method which sets landscapeHeight/portraitHeight to the appropriate values, then calls [self updateViewConstraints] to modify the height constraint.
和你一样,我的键盘有一个手势识别器,可以在短/高值之间切换键盘高度。我的手势识别器调用一个方法,该方法将landscape - height /portraitHeight设置为适当的值,然后调用[self updateviewconstraint]来修改高度约束。
I'm using two separate gesture recognizers; one for swipe up, another for swipe down. You could replace those with a single pan gesture recognizer which continues to track while the finger is still down, but I don't think you could adjust the height in real time while tracking.
我使用两个不同的手势识别器;一个向上滑动,另一个向下滑动。你可以用一个pan手势识别器来代替这些手势识别器,它可以在手指还在下方的时候继续跟踪,但我认为你不能在跟踪的时候实时调整高度。
#1
1
Please look at the accepted answer from @skyline75489-- which is the only solution that worked for me.
请查看@skyline75489的公认答案——这是唯一对我有效的解决方案。
Like you, my keyboard has a gesture recognizer that toggles the keyboard height between short/tall values. My gesture recognizer calls a method which sets landscapeHeight/portraitHeight to the appropriate values, then calls [self updateViewConstraints] to modify the height constraint.
和你一样,我的键盘有一个手势识别器,可以在短/高值之间切换键盘高度。我的手势识别器调用一个方法,该方法将landscape - height /portraitHeight设置为适当的值,然后调用[self updateviewconstraint]来修改高度约束。
I'm using two separate gesture recognizers; one for swipe up, another for swipe down. You could replace those with a single pan gesture recognizer which continues to track while the finger is still down, but I don't think you could adjust the height in real time while tracking.
我使用两个不同的手势识别器;一个向上滑动,另一个向下滑动。你可以用一个pan手势识别器来代替这些手势识别器,它可以在手指还在下方的时候继续跟踪,但我认为你不能在跟踪的时候实时调整高度。