如何在iOS 8中检测自定义键盘扩展中的方向更改? [英] How to detect Orientation Change in Custom Keyboard Extension in 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屋!