I am trying to set the bottom constraint to the height of the keyboard (and plus 4.0 for a bit of spacing). However For the first bit I am getting the following error;
Cannot assign value of type CGFloat to NSLayoutConstraint
I thought they were both CGFloat values, how can I convert the NSLayoutConstraint value to a CGFloat ? (so then I can add spacing)
func keyboardWillShow(n:NSNotification) {
let d = n.userInfo!
var r = (d[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue()
r = self.titleView.convertRect(r, fromView:nil)
self.titleView.contentInset.bottom = r.size.height
self.titleView.scrollIndicatorInsets.bottom = r.size.height
self.keyboardShowing = true
guard let keyboardHeight = (n.userInfo! as NSDictionary).objectForKey(UIKeyboardFrameBeginUserInfoKey)?.CGRectValue.size.height else {
return
}
buttonBottomConstant = keyboardHeight
}
Swift 5.5
Make sure you call the attribute constant on the NSLayoutConstraint instance variable, for you it will be
buttonBottomConstant.constant = keyboardHeight
You were missing .constant
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With