【问题标题】:iOS8 Keyboard OrientationiOS8 键盘方向
【发布时间】:2014-10-01 23:27:26
【问题描述】:

在我们的应用程序中,我们总是强制屏幕的方向。在 iOS8 之前,键盘的方向与状态栏的方向相关联,但现在在 iOS8 中似乎并非如此。

现在我们看到的情况是我们的屏幕(和状态栏)将正确地横向定位,但键盘仍然是纵向的。为了更正,我们必须在键盘以横向显示之前将设备从横向移动到纵向再到横向。

如果键盘方向不再与状态栏绑定,有没有办法也强制键盘方向?

编辑: 此代码适用于 iOS6 和 7。它用于更改状态栏的方向(也用于更改键盘的方向)和转换屏幕。

        [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
        if( isIpad() )
        {
            self.navigationController.view.center = CGPointMake( 374.0, 512.0 );
            self.navigationController.view.transform = CGAffineTransformMakeRotation( GlobalInfo::degreesToRadians( 90 ) )  ;
            self.navigationController.view.bounds = CGRectMake( 0, 0, 1024, 748 );
        }
        else
        {
            self.navigationController.view.center = CGPointMake( 150.0, 240.0 );
            self.navigationController.view.transform = CGAffineTransformMakeRotation( GlobalInfo::degreesToRadians( 90 ) )  ;
            self.navigationController.view.bounds = CGRectMake( 0, 0, 480, 300 );
        }

【问题讨论】:

  • 欢迎来到 StackOverflow。您能否说出您已经尝试过或研究过的问题的问题?这个问题似乎太宽泛了。
  • 谢谢,我添加了我们用来转换屏幕的代码。

标签: keyboard ios8 orientation


【解决方案1】:

在 iOS8 之前,它们的键盘方向与状态栏的方向相关,但在 iOS8 中,它与设备的方向相关。您可以使用以下代码强制设备的方向。

// Note that UIInterfaceOrientationLandscapeLeft is equal to UIDeviceOrientationLandscapeRight (and vice versa).
// This is because rotating the device to the left requires rotating the content to the right.

[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeLeft] forKey:@"orientation"];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-16
    • 1970-01-01
    • 2015-06-10
    • 1970-01-01
    • 1970-01-01
    • 2014-07-28
    • 2014-11-29
    相关资源
    最近更新 更多