gpt4 book ai didi

ios - 在 iOS 9 中更改方向

转载 作者:行者123 更新时间:2023-12-01 18:47:21 31 4
gpt4 key购买 nike

我的应用程序将以横向启动,只有一个 View 可以更改为纵向,其中有一个按钮,我单击此按钮将方向更改为纵向。
它在 iPad(iOS 8.4,部署目标:7.0)上按预期运行,我制作了一个 iPhone 版本,我只是对 UI 进行了一些调整,它在 iPhone 6 Plus 模拟器上运行(基础 SDK:9.1,部署目标: 7.0),但是换向按钮不起作用。
我想知道如何在 iOS 9 中实现它;
下面是我的代码:

- (void)changeOrientation
{
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];


if(orientation==UIInterfaceOrientationLandscapeLeft||orientation==UIInterfaceOrientationLandscapeRight){



NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];

if (orientation==UIInterfaceOrientationLandscapeLeft) {

value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
}else {

value = [NSNumber numberWithInt:UIInterfaceOrientationPortraitUpsideDown];
}

[[UIDevice currentDevice] setValue:value forKey:@"orientation"];

[[NSNotificationCenter defaultCenter] postNotificationName:@"ScreenToPortrait" object:nil];
}else{



NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
if (orientation==UIInterfaceOrientationPortrait) {
value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
}else {
value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
}


[[UIDevice currentDevice] setValue:value forKey:@"orientation"];

[[NSNotificationCenter defaultCenter] postNotificationName:@"ScreenToLandscapeLeft" object:nil];
}

[UIViewController attemptRotationToDeviceOrientation];

}

最佳答案

这适用于iOS9

NSNumber *orientationValue = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue: orientationValue forKey:@"orientation"];
  • 转至 General从应用程序目标选​​项卡,并启用所有方向。
  • 对于仅支持横向的所有 View ,请执行 supportedInterfaceOrientations()并返回横向值。
  • 关于ios - 在 iOS 9 中更改方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34451065/

    31 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com