objective-c - AppDelegate 中的方向检测

标签 objective-c ios orientation ios6 uistoryboard

这是在我的 AppDelegate 中,并在方向更改时运行。当应用程序加载时,它总是以纵向模式加载。如果我在设备处于横向模式时加载应用程序,这仍然会像设备处于纵向模式一样执行。这是我遇到的第一个问题。第二个是加载后,当我将设备从纵向旋转到横向时,会出现断线,如下所示:

-(void)setOrientationView
{

    UIDevice *currentDevice = [UIDevice currentDevice];
    [currentDevice endGeneratingDeviceOrientationNotifications];
    UIDeviceOrientation theOr = currentDevice.orientation;

    if ( UIDeviceOrientationIsLandscape(theOr) && !isLandVisible )
    {
        NSLog(@"setLand");
        isLandVisible = YES;
        isPortVisible = NO;

        [self.window.rootViewController pushViewController:portCont animated:YES];   // <Thread 1: breakpoint 2.1

    }

    if( UIDeviceOrientationIsPortrait(theOr) && !isPortVisible )
    {
        NSLog(@"setPort");
        isPortVisible = YES;
        isLandVisible = NO;

        [self.window.rootViewController pushViewController:portCont animated:YES];

    }
    [currentDevice beginGeneratingDeviceOrientationNotifications];

}

我正在努力支持加载时的两个方向,使用 Storyboard 应用程序,并且在查看 View 后不关闭 View (防止重新加载 UIWebViews 所必需的)。所以有两个问题超出了我的范围。谢谢。

最佳答案

Advanced App Tricks iOS App Programming Guide 的部分有一些关于 Launching in Landscape Mode 的指南。 ,您的答案可能就在这几行之内(如果可能的话)。特别要照顾UIInterfaceOrientation在您的 Info.plist文件。

关于objective-c - AppDelegate 中的方向检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12771377/

相关文章:

objective-c - NSZombieEnabled 只适用于 Objective-C 代码吗?

ios - 无法在 iOS 上与 Chrome 深度链接

swift - 自动布局 [Snapkit] 更改旋转约束

ios objc_getClass 和 objc_lookUpClass 有什么区别

ios - 角标(Badge)在右栏按钮项目上的稳定位置

CSS if else 条件,移动纵向或横向

ios - 带有 GPUImageBuffer 目标的 GPUImagePicture?

ios - 使用 PHAsset 获取图片时避免重复

objective-c - 有没有办法识别 NSNotification/NSEvent 来自哪个应用程序?

iphone - 使用 NSPredicate 从复杂的 JSON 资源中过滤 NSArray