如何在iOS 8中检测自定义键盘扩展中的方向更改? [英] How to detect Orientation Change in Custom Keyboard Extension in iOS 8?

查看:303
本文介绍了如何在iOS 8中检测自定义键盘扩展中的方向更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在自定义键盘扩展中,我们无法使用

In Custom Keyboard Extension , we can't use

`didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation` 

sharedApplication

我需要在旋转时检测键盘上的纵向或横向。

I need to detect portrait or landscape in keyboard when rotate.

如何在自定义键盘扩展中检测方向更改?

How can i detect when orientation change in Custom Keyboard extension?

推荐答案

为了在方向更改时更新自定义键盘,请在<$中覆盖 viewDidLayoutSubviews C $ C> UIInputViewController 。据我所知,当旋转发生时,总是调用此方法。

In order to update your custom keyboard when the orientation changes, override viewDidLayoutSubviews in the UIInputViewController. As far as I can tell, when a rotation occurs this method is always called.

此外,正如传统的 [UIApplication sharedApplication] statusBarOrientation] 不起作用,确定当前方向使用以下代码段:

Additionally, as the traditional [UIApplication sharedApplication] statusBarOrientation] doesn't work, to determine the current orientation use the following snippet:

if([UIScreen mainScreen].bounds.size.width < [UIScreen mainScreen].bounds.size.height){
    //Keyboard is in Portrait
}
else{
    //Keyboard is in Landscape
}

希望这有帮助!

这篇关于如何在iOS 8中检测自定义键盘扩展中的方向更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆