Keyboard Issue in Landscape Orientation - Xcode - Swift

情到浓时终转凉″ 提交于 2020-05-13 18:16:12

问题


I have a Share extension for my iOS app and the extension requires the use of a keyboard. It seems as though I cannot control the orientation of the view controller of the extension, so when the device is put in landscape mode, the keyboard turns sideways, but off the screen. This makes it so that the user cannot use the keyboard when in landscape mode. How can I change the coordinates of the keyboard on screen, and how do I detect the orientation of the device? I am perplexed by this issue and any feedback would be appreciated.


回答1:


  • To detect the orientation:

    if(UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation))
    {            
        println("landscape")
    }
    
    if(UIDeviceOrientationIsPortrait(UIDevice.currentDevice().orientation))
    {
        println("portrait")
    }
    
  • To detect the orientation change (in a UIViewController):

    override func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation) {
        // your code
    }
    

You can detect the orientation change and the orientation you have



来源:https://stackoverflow.com/questions/29495554/keyboard-issue-in-landscape-orientation-xcode-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!