[英]Keyboard Issue in Landscape Orientation - Xcode - Swift
我的iOS應用程序有一個共享擴展程序,該擴展程序需要使用鍵盤。 似乎我無法控制擴展程序的視圖控制器的方向,因此,當設備處於橫向模式時,鍵盤會側向旋轉,但會離開屏幕。 這樣可以使用戶在橫向模式下無法使用鍵盤。 如何更改屏幕上鍵盤的坐標,以及如何檢測設備的方向? 我對此問題感到困惑,任何反饋將不勝感激。
要檢測方向:
if(UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation)) { println("landscape") } if(UIDeviceOrientationIsPortrait(UIDevice.currentDevice().orientation)) { println("portrait") }
要檢測方向變化(在UIViewController中):
override func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation) { // your code }
您可以檢測方向變化和方向
在您的viewcontroller中添加此方法
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
if (self.view.bounds.size.width > self.view.bounds.size.height) {
//landscape
} else {
//portrait
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.