0

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.

nurnachman
  • 4,468
  • 2
  • 37
  • 40
Bis
  • 713
  • 1
  • 5
  • 7

3 Answers3

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