gpt4 book ai didi

iphone - UIOrientation 返回 0 或 5

转载 作者:太空狗 更新时间:2023-10-30 03:58:35 24 4
gpt4 key购买 nike

我正在运行一个简单的函数,该函数会在多个区域被调用,以帮助处理方向更改期间 iPad 应用程序上的布局。它看起来像这样:

- (void) getWidthAndHeightForOrientation:(UIInterfaceOrientation)orientation {
NSLog(@"New Orientation: %d",orientation);
end

我在很多地方都这样调用它:

[self getWidthAndHeightForOrientation: [[UIDevice currentDevice] orientation]];

该函数通常有一些简单的代码,在方向为纵向或横向时运行。不幸的是,当应用程序以位置 1 启动时,它没有按预期工作。结果我得到 0。稍后,如果以相同方式调用该函数,但设备从未旋转过,我会返回值 5。这是什么意思?为什么会抛出这些值?

简而言之,为什么 [[UIDevice currentDevice] orientation] 会抛出 0 或 5 而不是 1 到 4 之间的任何值?

更新:

由于处理方向的方式,我一直在我的代码中发现错误,所以我写了一篇关于如何处理 UIDevice 或 UIInterface 方向的权威文章:http://www.donttrustthisguy.com/orientating-yourself-in-ios

最佳答案

您是否看过 UIInterfaceOrientation 的枚举值?来自文档:

typedef enum {
UIDeviceOrientationUnknown,
UIDeviceOrientationPortrait,
UIDeviceOrientationPortraitUpsideDown,
UIDeviceOrientationLandscapeLeft,
UIDeviceOrientationLandscapeRight,
UIDeviceOrientationFaceUp,
UIDeviceOrientationFaceDown
} UIDeviceOrientation;

因此可以想象它可以是 0-6 之间的任何值。

编辑:也许您应该使用 UIViewController 上的方法(willRotateToInterfaceOrientation:duration: 等),而不是调用 orientation UIDevice?

关于iphone - UIOrientation 返回 0 或 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3327458/

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