cocos2d v3 在应用程序使用过程中重新定向屏幕

2024-03-22

所以在 cocos2d 中(我相信我使用的是 v2.1),我这样做是为了锁定和设置方向:

        AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

    const UIInterfaceOrientation ORIENTATION = delegate.navController.interfaceOrientation;
    delegate.navController.
    delegate.navController.screenOrientation = ORIENTATION == UIInterfaceOrientationMaskPortrait;
    UIViewController *mVC = [[UIViewController alloc] init];
    [delegate.navController presentModalViewController:mVC animated:NO];
    [delegate.navController dismissModalViewControllerAnimated:NO];

AppDelegate 中添加了一些功能。 我似乎无法在 iOS7 和 cocos2d v3 中获得相同的结果。

我已经深入研究了一下,正确的功能似乎已经就位,但似乎无法设置全局变量来设置方向并仅在特定时间返回我想要的方向。有人能指出我正确的道路吗?我认为我错过了一些非常小的东西,因为正确的代码似乎已经在那里了。

这是我的 AppDelegate 的代码

@implementation AppDelegate

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self setupCocos2dWithOptions:@{
        CCSetupShowDebugStats: @(NO),
    }];

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

return YES;

}

-(CCScene *)startScene
{
    return [HomeScreen scene];
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

我的代码从未遇到过 interfaceOrientation 函数。

想法??!?


经过几天的闲逛,我找到了解决方案:

在 AppDelegate 中我需要这个函数:

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if (!self.lockedToOrientation) {
        if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone ){
            return UIInterfaceOrientationMaskPortrait;
        }

        return UIInterfaceOrientationMaskPortrait;
    }
    else {
        return self.lockedToOrientation;
    }
}

Where

@property UIInterfaceOrientationMask lockedToOrientation;

希望这对某人有帮助!

Cheers.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

cocos2d v3 在应用程序使用过程中重新定向屏幕 的相关文章

随机推荐

  • python urllib2文件发送问题

    我想通过 python 将文件发布到服务器 为此我需要将此文件命名为 xmlfile 以便服务器识别输入 import urllib2 url http somedomain to send open test xml read data
  • 在 Backbone 渲染方法中调用 jQuery 插件

    我在 Backbone 中有一个渲染方法 基本上是这样的 render function tmpl this template attrs appendTo this el return this 这是从路由器操作中调用的 action f
  • Azure-runbook 中的 New-PSSession (ARM)

    对于经典门户 ASM 中的 Azure VM 我能够获得 所需的凭据Get AutomationPSCredential and the ConnectionURI with Connect AzureVM ps1 https galler
  • vh 单元行为不一致

    我有一个伪元素 悬停时出现 height 0 4vh 高度不会改变 只有宽度会改变 然而 由于某种原因 在某些条件下 不同伪元素的高度不同 这里的两条深色线都有height 0 4vh 我用这个小提琴来演示 但意识到这种奇怪的情况是否发生取
  • 无法获取已安装模块的绝对路径

    我遇到了一个问题 我认为这与我的 package json 或 cordova 平台的版本有关 当我尝试运行ionic state restore它返回以下输出 Attempting to restore your Ionic applic
  • HTML5代码元素-语言类

    HTML5 code 元素有一个可选的 class language 属性 https html spec whatwg org multipage semantics html the code element定义代码片段的语言 规范中的
  • 像 Uber Android 一样在地图上旋转标记和移动动画

    我正在从事一个类似于 UBER Lyft 或 OLA 的项目 家里的地图上有可用的移动汽车 我正在寻找某种图书馆 它可以让汽车像 UBER 一样顺利移动和转弯 现在 我可以使用下面的代码将汽车从一个经纬度平稳地移动到另一个纬度经度 但棘手的
  • 在 Windows CE 5 上安装我的程序

    我正在完成 Windows CE 5 的应用程序 我想知道在 CE 5 设备上安装该应用程序的最简单方法是什么 在 VS8 中点击 发布 会生成一个安装程序 但该安装程序与 CE 5 不兼容 在 Windows CE 5 上安装应用程序的简
  • 在 QThread 中启动 QTimer

    我正在尝试在特定线程中启动 QTimer 但是 计时器似乎没有执行 也没有打印任何内容 与定时器 槽或线程有关吗 main cpp include MyThread h include
  • 在设定的字符数和长度下,可以有多少个唯一的字符串?

    如果我有两个角色 a b 和长度为三 aaa aab 我如何计算我可以用它组成多少个唯一的字符串 以及数学方法是什么 它是否正确 val 1 amountCharacters 2 length 3 for i 1 i lt length i
  • bash:〜/ .bash_profile:没有这样的文件或目录[关闭]

    Closed 这个问题是无法重现或由拼写错误引起 help closed questions 目前不接受答案 我不断收到此错误 bash bash profile No such file or directory 这是我的 bash pr
  • 如何忽略 Snakemake 的“自上次执行以来参数已更改”?

    由于 conda 环境不活跃 工作流程的一些非常晚的作业崩溃了 现在 当我尝试使用重新运行时snakemake deploy all ignore incomplete所有作业都会从头开始重新运行 原因如下 Reason Params ha
  • 如何在c++中显示实时时间

    有人可以告诉我如何在 C 中显示实时时间吗 我的意思是 当程序运行时 您可以看到秒和 或分钟倒计时 就像挂在墙上的真实时钟一样 这就是我所拥有的 int main time t rawtime creates and object of t
  • 通过 SOCKS 代理使用 Hadoop?

    所以我们的Hadoop集群运行在一些节点上 并且只能从这些节点访问 您可以通过 SSH 连接到它们并完成您的工作 因为这很烦人 但 可以理解 没有人会尝试配置访问控制 以便某些人可以从外部使用它 我正在尝试下一个最好的方法 即使用 SSH
  • Javascript - 如何查找希伯来语?

    我正在尝试查找字符串是否以 RTL 语言 希伯来语开头 第一个字母 有任何想法吗 这将找到编码在以下内容中的希伯来字母Hebrew http www alanwood net unicode hebrew htmlUnicode 代码点范围
  • 对 numpy.c_ 文档和示例代码感到困惑

    我多次阅读有关 numpy c 的文档 但仍然感到困惑 据说 将切片对象转换为沿第二轴的串联 在下面的文档中 谁能在下面的示例中澄清什么是切片对象 什么是第二轴 我看到它们都是一维的 并且混淆了第二轴的来源 在 Windows 上使用 Py
  • PHP $_SERVER['SERVER_NAME'] 正确使用

    菜鸟问题在这里 我正在使用 php 构建一个交互式网站 并且我决定制作一个交互式菜单 嗯 我的菜单包含一个名为 menu php 的文件 我不知道为什么 但是当我点击这个链接时 它看起来像这样 http localhost mysite 本
  • SEGMENT_START("text-segment", 0x400000) 代表什么?

    我正在学习可执行二进制文件的布局 我的最终目标是分析特定可执行文件中可以重构 在其源代码中 以减少编译输出大小的内容 我一直在使用https www embeddedlated com showarticle 900 php https w
  • Django 检查相关对象是否存在错误:RelatedObjectDoesNotExist

    我有一个方法has related object在我的模型中需要检查相关对象是否存在 class Business base name models CharField max length 100 blank True null True
  • cocos2d v3 在应用程序使用过程中重新定向屏幕

    所以在 cocos2d 中 我相信我使用的是 v2 1 我这样做是为了锁定和设置方向 AppDelegate delegate AppDelegate UIApplication sharedApplication delegate con