• <small id='rrgZf'></small><noframes id='rrgZf'>

    <legend id='rrgZf'><style id='rrgZf'><dir id='rrgZf'><q id='rrgZf'></q></dir></style></legend>

        <tfoot id='rrgZf'></tfoot>
      1. <i id='rrgZf'><tr id='rrgZf'><dt id='rrgZf'><q id='rrgZf'><span id='rrgZf'><b id='rrgZf'><form id='rrgZf'><ins id='rrgZf'></ins><ul id='rrgZf'></ul><sub id='rrgZf'></sub></form><legend id='rrgZf'></legend><bdo id='rrgZf'><pre id='rrgZf'><center id='rrgZf'></center></pre></bdo></b><th id='rrgZf'></th></span></q></dt></tr></i><div id='rrgZf'><tfoot id='rrgZf'></tfoot><dl id='rrgZf'><fieldset id='rrgZf'></fieldset></dl></div>
          <bdo id='rrgZf'></bdo><ul id='rrgZf'></ul>

        iOS 6 - 如何在方向改变时运行自定义代码

        时间:2024-04-14
          <tbody id='K6t4Y'></tbody>
        <legend id='K6t4Y'><style id='K6t4Y'><dir id='K6t4Y'><q id='K6t4Y'></q></dir></style></legend>

        <small id='K6t4Y'></small><noframes id='K6t4Y'>

        <i id='K6t4Y'><tr id='K6t4Y'><dt id='K6t4Y'><q id='K6t4Y'><span id='K6t4Y'><b id='K6t4Y'><form id='K6t4Y'><ins id='K6t4Y'></ins><ul id='K6t4Y'></ul><sub id='K6t4Y'></sub></form><legend id='K6t4Y'></legend><bdo id='K6t4Y'><pre id='K6t4Y'><center id='K6t4Y'></center></pre></bdo></b><th id='K6t4Y'></th></span></q></dt></tr></i><div id='K6t4Y'><tfoot id='K6t4Y'></tfoot><dl id='K6t4Y'><fieldset id='K6t4Y'></fieldset></dl></div>
            <bdo id='K6t4Y'></bdo><ul id='K6t4Y'></ul>

                • <tfoot id='K6t4Y'></tfoot>
                • 本文介绍了iOS 6 - 如何在方向改变时运行自定义代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在创建一个游戏,它允许设备处于横向左或横向右方向,并且玩家可以在暂停时更改方向.当他们这样做时,我需要更改游戏根据方向解释加速度计的方式.

                  I'm creating a game that allows the device to be in either landscape-left or landscape-right orientation, and the player can change the orientation while it's paused. When they do I need to change the way the game interprets the accelerometer based on the orientation.

                  在 iOS 5 中,我使用 willRotateToInterfaceOrientation 来捕获更改并更改我的变量,但在 iOS6 中已弃用.我现有的代码如下所示:

                  In iOS 5 I used the willRotateToInterfaceOrientation to catch changes and change my variables, but that's deprecated in iOS6. My existing code looks like this:

                      if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)      
                          rect = screenRect;
                  
                      else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight){
                          rect.size = CGSizeMake( screenRect.size.height, screenRect.size.width );
                      GameEngine *engine = [GameEngine sharedEngine];
                      if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft){
                          engine.orientation = -1;
                      } else {
                          engine.orientation = 1;
                      }
                  }
                  

                  我知道替换的是 UIViewController 类中的 viewWillLayoutSubviews 方法.我正在 cocos2d 2.1 中构建这个游戏,并且在演示项目中似乎没有 UIViewController 类,所以我不清楚如何合并它以及代码应该如何看起来才能使其工作.

                  I understand that the replacement is the viewWillLayoutSubviews method in the UIViewController class. I'm building this game in cocos2d 2.1 and there doesn't appear to be a UIViewController class in the demo project, so I'm not clear on how to incorporate it and how the code should look in order to make this work.

                  推荐答案

                  监听设备方向变化:

                  [[NSNotificationCenter defaultCenter] 
                         addObserver:self
                            selector:@selector(deviceOrientationDidChangeNotification:) 
                                name:UIDeviceOrientationDidChangeNotification 
                              object:nil];
                  

                  收到通知后,从 UIDevice 获取设备方向:

                  When notified, get the device orientation from UIDevice:

                  - (void)deviceOrientationDidChangeNotification:(NSNotification*)note
                  {
                      UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
                      switch (orientation)
                      {
                          // etc... 
                      }
                  }
                  

                  这篇关于iOS 6 - 如何在方向改变时运行自定义代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:cocos2d 支持 ARC 吗? 下一篇:[[CCDirector sharedDirector]winSize] 错误

                  相关文章

                  <tfoot id='TmFfb'></tfoot>

                  <legend id='TmFfb'><style id='TmFfb'><dir id='TmFfb'><q id='TmFfb'></q></dir></style></legend>

                  <small id='TmFfb'></small><noframes id='TmFfb'>

                  <i id='TmFfb'><tr id='TmFfb'><dt id='TmFfb'><q id='TmFfb'><span id='TmFfb'><b id='TmFfb'><form id='TmFfb'><ins id='TmFfb'></ins><ul id='TmFfb'></ul><sub id='TmFfb'></sub></form><legend id='TmFfb'></legend><bdo id='TmFfb'><pre id='TmFfb'><center id='TmFfb'></center></pre></bdo></b><th id='TmFfb'></th></span></q></dt></tr></i><div id='TmFfb'><tfoot id='TmFfb'></tfoot><dl id='TmFfb'><fieldset id='TmFfb'></fieldset></dl></div>

                        <bdo id='TmFfb'></bdo><ul id='TmFfb'></ul>