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

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

      2. 如何在设备方向(不是界面方向)事件上订阅自己?

        How to subscribe self on the event of Device Orientation(not interface orientation)?(如何在设备方向(不是界面方向)事件上订阅自己?)
        <legend id='vaS3R'><style id='vaS3R'><dir id='vaS3R'><q id='vaS3R'></q></dir></style></legend>

        <tfoot id='vaS3R'></tfoot>
        • <small id='vaS3R'></small><noframes id='vaS3R'>

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

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

                • 本文介绍了如何在设备方向(不是界面方向)事件上订阅自己?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在我的应用程序中,我想在设备旋转(方向改变)的情况下调用 CCScene myscene 中的一些方法.我禁用了自动旋转(因为我不希望它发生).

                  in my app i want to call some method in CCScene myscene in the case of device rotation(orientation change).I disabled the autorotation(because i want it not to happen).

                  问题是:我想根据我的设备方向改变场景中的重力.我的代码:

                  The issue is: i want to change gravity in the scene depending on my device orientation. My code :

                  -(void) onEnter
                  {
                      [super onEnter];
                      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notification_OrientationWillChange:) name:UIApplicationWillChangeStatusBarOrientationNotification object:nil];
                      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notification_OrientationDidChange:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
                  }
                  -(void) onExit
                  {
                      //[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillChangeStatusBarOrientationNotification object:nil];
                      //[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
                  }
                  -(void)notification_OrientationWillChange:(NSNotification*)n
                  {
                      orientation = (UIInterfaceOrientation)[[n.userInfo objectForKey:UIApplicationStatusBarOrientationUserInfoKey] intValue];
                  }
                  -(void)notification_OrientationDidChange:(NSNotification*)n
                  {
                      if (orientation == UIInterfaceOrientationLandscapeLeft) {
                          b2Vec2 gravity( 0, -10);
                          world->SetGravity(gravity);
                      }
                      if (orientation == UIInterfaceOrientationLandscapeRight) {
                          b2Vec2 gravity( 0, 10);
                          world->SetGravity(gravity);
                      }
                  }
                  

                  但在这种情况下,我只能在启用自动旋转的情况下收到通知.(如果禁用,设备实际上不会更改状态栏方向)你能帮帮我吗?

                  But in this case i can get notifications only in the case of autorotation enabled.(if it disabled, device is actually don't change it status bar orientation) Can you help me?

                  推荐答案

                  [[NSNotificationCenter defaultCenter] addObserver:self
                                                           selector:@selector(orientationChanged:)
                                                               name:@"UIDeviceOrientationDidChangeNotification" 
                                                             object:nil];
                  
                  
                  
                  - (void)orientationChanged:(NSNotification *)notification{  
                      UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
                  
                      //do stuff
                      NSLog(@"Orientation changed");          
                  }
                  

                  您必须检查设备方向而不是状态栏.

                  You must check for Device orientation not status bar.

                  typedef enum {
                          UIDeviceOrientationUnknown,
                          UIDeviceOrientationPortrait,            // Device oriented vertically, home button on the bottom
                          UIDeviceOrientationPortraitUpsideDown,  // Device oriented vertically, home button on the top
                          UIDeviceOrientationLandscapeLeft,       // Device oriented horizontally, home button on the right
                          UIDeviceOrientationLandscapeRight,      // Device oriented horizontally, home button on the left
                          UIDeviceOrientationFaceUp,              // Device oriented flat, face up
                          UIDeviceOrientationFaceDown             // Device oriented flat, face down
                      } UIDeviceOrientation;
                  

                  这篇关于如何在设备方向(不是界面方向)事件上订阅自己?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
                  Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)
                  Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))
                  Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
                  Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)
                  [ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)
                  <tfoot id='z4YlY'></tfoot>
                  <i id='z4YlY'><tr id='z4YlY'><dt id='z4YlY'><q id='z4YlY'><span id='z4YlY'><b id='z4YlY'><form id='z4YlY'><ins id='z4YlY'></ins><ul id='z4YlY'></ul><sub id='z4YlY'></sub></form><legend id='z4YlY'></legend><bdo id='z4YlY'><pre id='z4YlY'><center id='z4YlY'></center></pre></bdo></b><th id='z4YlY'></th></span></q></dt></tr></i><div id='z4YlY'><tfoot id='z4YlY'></tfoot><dl id='z4YlY'><fieldset id='z4YlY'></fieldset></dl></div>
                    <bdo id='z4YlY'></bdo><ul id='z4YlY'></ul>
                        <tbody id='z4YlY'></tbody>
                        <legend id='z4YlY'><style id='z4YlY'><dir id='z4YlY'><q id='z4YlY'></q></dir></style></legend>

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