问题
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