• <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 - 如何在方向改变时运行自定义代码

        iOS 6 - How to run custom code when orientation changes(iOS 6 - 如何在方向改变时运行自定义代码)
          <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 - 如何在方向改变时运行自定义代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  what#39;s property copy means in Cocoa#39;s Framework?(like UITabBar#39;s items property)(Cocoa 框架中的属性副本是什么意思?(如 UITabBar 的 items 属性))
                  Can`t copy file from bundle to documents directory in iOS(无法将文件从捆绑包复制到 iOS 中的文档目录)
                  When compiling for multiple targets in XCode, how do i ensure that certain files will not be included one target(在 XCode 中为多个目标编译时,我如何确保某些文件不会包含在一个目标中)
                  Automatically copy property values from one object to another of a different type but the same protocol (Objective-C)(自动将属性值从一个对象复制到另一个类型不同但协议相同的对象 (Objective-C))
                  Copy text to clipboard with iOS(使用 iOS 将文本复制到剪贴板)
                  How to copy text to clipboard/pasteboard with Swift(如何使用 Swift 将文本复制到剪贴板/粘贴板)
                  <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>

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