How to detect Orientation Change in Custom Keyboard Extension in iOS 8?

后端 未结 10 1918

In Custom Keyboard Extension , we can\'t use

`didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation` 

and

10条回答
  •  甜味超标
    2020-12-04 18:39

    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.

    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
    }
    

    Hopefully this helps!

提交回复
热议问题