【问题标题】:Device Orientation results in flipped node location设备方向导致节点位置翻转
【发布时间】:2015-10-14 09:31:00
【问题描述】:

我的代码很简单。我想将 SKSpriteNode 的位置更改为始终保持在设备屏幕的右下角。我在设备旋转时将我的 UIDeviceOrientationDidChangeNotification 方法称为“旋转”,它应该只是移动节点,但由于某种原因,它总是会翻转所需的位置,因此横向位置就是肖像应该在的位置,反之亦然。

我的代码如下:

用户界面

    - (void)rotated:(NSNotification *)notification {
            DeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
            if (UIDeviceOrientationIsLandscape(deviceOrientation) && !_isShowingLandscapeView)
                [self.node setPosition:bottom_right];
                _isShowingLandscapeView = YES;
            }
            else if (UIDeviceOrientationIsPortrait(deviceOrientation) && _isShowingLandscapeView)
            {
                [self.node setPosition:bottom_right];
                _isShowingLandscapeView = NO;
            }
        }

【问题讨论】:

  • deviceOrientation 来自哪里?
  • 对不起,我错过了那部分,但它包含在我的代码中。问题依旧,有什么建议吗?事实上,我什至不需要检查它是横向还是纵向,我应该能够指定右下角,但我只是尝试了一下。问题是当我指定右下角时它没有出现,句号。
  • 你是如何计算bottom_right的?
  • CGSizeMake(self.size.width/2 - btn_wd/2, btn_ht/2 - self.size.height/2);我的节点和场景的锚点位于中心。这就是我这样计算的原因。

标签: ios uideviceorientation


【解决方案1】:

好的,我所做的很简单。只需在您的 SKScene 上使用 UIButtons。返回到 UIViewController,从中调用 skscene 并添加按钮。您必须使用 NSNotification 中心将信息传递给按钮、标签等。

http://www.raywenderlich.com/forums/viewtopic.php?f=2&t=8843

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-25
    • 2020-07-25
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    • 2015-02-24
    相关资源
    最近更新 更多