CaptainCOOLGUY CaptainCOOLGUY - 19 days ago 6
Swift Question

How to find keyboard height using Swift

let frame = (info[UIKeyboardFrameEndUserInfoKey] as NSValue) as CGRect


does not work. Anybody know why this does not function as expected?

Error: 'NSValue' not convertible to 'CGRect'

Keep in mind that something like:

let curve = (info[UIKeyboardAnimationCurveUserInfoKey] as NSValue) as UInt


works fine.

Edit: Even Apple documentation indicates this is a glitch because of the following comment in Cocoa for
UIKeyboardAnimationCurveUserInfoKey


// NSValue of CGRect


Edit2: The debugger defines it as an NSConcreteValue. How can I convert it to a CGRect?

Answer
let frame = (info[UIKeyboardFrameEndUserInfoKey] as NSValue).CGRectValue()
Comments