gpt4 book ai didi

swift - 如何缩放窗口以适应所有设备?

转载 作者:行者123 更新时间:2023-11-30 10:01:38 28 4
gpt4 key购买 nike

我想知道如何缩放窗口以适应所有设备的相同尺寸。问题是,在某些潜水中,对象没有覆盖我想要的相同空间。

我有我的scaleMode = .ResizeFill,但问题是,如果我将其设置为.AspectFill,它不会出现在正确的位置。我认为问题是我在场景中添加了一个新的容器,但我不知道如何解决。

class GameViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

if let scene = GameScene(fileNamed:"GameScene") {
// Configure the view.
let skView = self.view as! SKView
skView.showsFPS = true
skView.showsNodeCount = true

/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = true

/* Set the scale mode to scale to fit the window */
scene.scaleMode = .ResizeFill
scene.position = view.center

skView.presentScene(scene)
}
}


override func didMoveToView(view: SKView) {
/* Setup your scene here */

scaleMode = .ResizeFill
node.position = view.center
// 3) Add the container to the scene
//addChild(node)
// 4) Set the sprite's x position
sprite.position = CGPointMake(radius, 0)
// 5) Add the sprite to the container
node.addChild(sprite)
// 6) Rotate the container
rotate()
sprite.color = UIColor.whiteColor()
sprite.colorBlendFactor = 1.0
sprite.zPosition = 4.0

circulo = SKSpriteNode(imageNamed: "circuloFondo2")
circulo.size = CGSize(width: 294, height: 294)
circulo.color = UIColor(red: 0.15, green: 0.15, blue: 0.15, alpha: 1)
circulo.colorBlendFactor = 1
circulo.alpha = 0.35
circulo.position = view.center
self.addChild(circulo)
circulo.zPosition = 1
}

This is an iPhone 5s enter image description here

最佳答案

  • 问题可能出在您绘制圆圈的代码中,您可能正在绘制所有屏幕尺寸具有相同半径的圆。
  • 您需要绘制具有相同半径的圆,而不是根据设备宽度提供圆的动态半径。

替换这个

circulo.size = CGSize(width: 294, height: 294)

使用以下代码片段

let padding:CGFloat =  40.0  
circulo.size = CGSize(width:view.frame.size.width - padding , height: view.frame.size.width - padding)

关于swift - 如何缩放窗口以适应所有设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38195082/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com