Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Swift SKSpiteNode定位iPhone V iPad_Ios_Iphone_Swift_Ipad - Fatal编程技术网

Ios Swift SKSpiteNode定位iPhone V iPad

Ios Swift SKSpiteNode定位iPhone V iPad,ios,iphone,swift,ipad,Ios,Iphone,Swift,Ipad,我已使用以下代码将节点定位在我的应用程序视图的左上角: health = SKSpriteNode(color: .green, size: CGSize(width: progressValue, height: 50)) health.position = CGPoint(x: -self.frame.width / 2, y: self.frame.height / 2) 这在所有iPhone模拟器中的位置都是正确的,范围从5到7个以上 然而,它并没有出现在任何iPad模拟器中。我已经将

我已使用以下代码将节点定位在我的应用程序视图的左上角:

health = SKSpriteNode(color: .green, size: CGSize(width: progressValue, height: 50))
health.position = CGPoint(x: -self.frame.width / 2, y: self.frame.height / 2)
这在所有iPhone模拟器中的位置都是正确的,范围从5到7个以上

然而,它并没有出现在任何iPad模拟器中。我已经将位置设置为midX和midY,看起来不错,只是上面显示的代码并不适用于所有iPhone

我错过了什么

对于iPhone v iPad,是否有其他方法在视图上定位节点,而不是使用视图的倍数?

已解决:

问题是scene scaleMode设置为.aspectFill,这对iPhone非常有效,但对iPad却没有

然而,resizeFill工作得很好,所以我就是这么做的

if UIDevice.current.userInterfaceIdiom == .pad {

                scene.scaleMode = .resizeFill

            }else{

                scene.scaleMode = .aspectFill


            }

我怀疑你可能在iPad屏幕旋转方面有问题。你有没有检查过你的iPad视图的高度和宽度,看看系统报告这些值是什么?@Scotthompson没有,我以前从来没有让应用程序与iPad兼容过,所以我不知道该怎么做。我假设根据视图的高度/宽度设置所有节点位置会像所有iPhone视图一样工作?