I am building a custom keyboard for iOS8. I want my keyboard to support portrait and landscape modes. How do I determine the device orientation? Getting device orientation doesn't currently work well in custom keyboards.
Asked
Active
Viewed 218 times
0
-
what exactly is the problem? what problems are you facing? – nurnachman Nov 02 '14 at 22:53
-
When My keyboard is in landscape mode How I will determine that the keyboard extension is in landscape mode. – Bis Nov 05 '14 at 14:05
-
i edited your question and answered it. hope i helped – nurnachman Nov 05 '14 at 19:16
3 Answers
1
willRotateToInterfaceOrientation
and didRotateFromInterfaceOrientation
can be used, although they are deprecated in iOS 8. Their replacement, willTransitionToTraitCollection
, isn't called upon rotation though likely because the trait collection doesn't change for the keyboard.

Jordan H
- 52,571
- 37
- 201
- 351
0
Unfortunately, the standard method for determining device orientation doesn't work yet in iOS8 custom keyboards.
You can determine the device orientation by checking the ratios between the width and the height of the device. height > width = portrait width > height = landscape

nurnachman
- 4,468
- 2
- 37
- 40
0
You can use this approach:
typedef NS_ENUM(NSInteger, InterfaceOrientationType)
{
InterfaceOrientationTypePortrait,
InterfaceOrientationTypeLandscape
};
- (InterfaceOrientationType)orientation
{
InterfaceOrientationType result;
if([UIScreen mainScreen].bounds.size.width < [UIScreen mainScreen].bounds.size.height)
{
result = InterfaceOrientationTypePortrait;
}
else
{
result = InterfaceOrientationTypeLandscape;
}
return result;
}

iOS Dev
- 4,143
- 5
- 30
- 58