簡體   English   中英

圖像不適合屏幕

[英]Image doesn't fit to screen

我在屏幕上有一張圖片:

    image = SKSpriteNode(imageNamed: "image.png")
    image.name = "leftside1"
    image.position = CGPoint(x: 0, y: 0)
    image.zPosition = 3


    self.addChild(image)

圖像的寬度為w250xh1920-當我顯示屏幕時,圖像不適合屏幕,其上下尺寸較大,但是我在上一場景中設置了AspectFit:

 nextScene!.scaleMode = .aspectFit

嘗試AspectFill無法解決我的問題。 有什么建議嗎? 謝謝!

嘗試將圖像尺寸設置為這樣的場景尺寸。

if let size = nextScene?.size {
    image.size = size
}

這是如何動態計算寬度的示例。

if let size = nextScene?.size {
    // Calculate ratio
    let ratio = size.width / size.height
    // Multiple image width by ratio
    let width = image.size.width * ratio
    // Create a new CGSize
    let newSize = CGSize(width: width, height: size.height)

    image.size = newSize
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM