0

我正在为 iOS8 构建一个自定义键盘。我希望我的键盘支持纵向和横向模式。如何确定设备方向?获取设备方向目前在自定义键盘中效果不佳。

4

3 回答 3

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.

于 2014-11-15T05:08:55.417 回答
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

于 2014-11-05T19:16:02.083 回答
0

您可以使用这种方法:

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;
}
于 2014-11-07T16:32:28.743 回答