What you're interested in is not the device orientation, but the interface orientation. Try using self.interfaceOrientation
(where self
is your view controller). You can also get this from [[UIApplication sharedApplication] statusBarOrientation]
.
That being said, you probably shouldn't be using the interface orientation at all to find out where the keyboard is. The keyboard generates notifications when it appears and moves around, which include position information. Take a look at the UIKeyboardWillShowNotification
and UIKeyboardWillChangeFrameNotification
. They have position information in their userInfo dictionary under the UIKeyboardFrameBeginUserInfoKey
and UIKeyboardFrameEndUserInfoKey
keys which will tell you where the keyboard will be.