【发布时间】: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);我的节点和场景的锚点位于中心。这就是我这样计算的原因。