gpt4 book ai didi

ios - 设备方向没有得到。

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:03:58 25 4
gpt4 key购买 nike

目前我正在使用 IOS 7,我的问题是我无法在 ViewDidLoad 方法中获取当前设备的方向。

- (BOOL)shouldAutorotate
{
return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskAll);

}
- (void)viewDidLoad
{
[super viewDidLoad];

if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)){
NSLog(@"i am in landscape mode");
}
if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)){
NSLog(@"i am in portrait mode");
}
}

我在我的 FirstViewController.m 中编写了这段代码,当我运行我的应用程序时,没有条件变为真,任何人都可以帮助我为什么即使我以纵向模式运行我的应用程序也没有条件变为真。提前致谢。

最佳答案

试试这个。

UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;

if(UIInterfaceOrientationIsLandscape(orientation)) {
//Landscape mode
}
else
{
//Portrait mode
}

编辑:使用UIInterfaceOrientationIsLandscapeUIInterfaceOrientationIsPortrait 方法找到方向模式

关于ios - 设备方向没有得到。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25661792/

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