使用 Swift 的 SKVideoNode 中的垂直视频方向问题

Mr_*_*r_P 3 video ios avplayer skvideonode swift

下面的代码显示了我的视频文件在正确的 zPosition 中,以及我正在使用的其他元素,创建了一个背景视频。

我遇到的问题是垂直视频(1080x1920 像素)逆时针旋转 90 度,并被拉伸以适合横向视频。如何在不牺牲使用 SKVideoNode 和 zPosition 的需要的情况下确保正确的方向?

let videoNode: SKVideoNode? = {

    guard let urlString = Bundle.main.path(forResource: "merry", ofType: "mov") else {
        return nil
    }

    let url = URL(fileURLWithPath: urlString)
    let item = AVPlayerItem(url: url)
    player = AVPlayer(playerItem: item)

    return SKVideoNode(avPlayer: player)

}()

videoNode?.position = CGPoint( x: frame.midX, y: frame.midY)
videoNode?.size = self.frame.size
videoNode?.zPosition = 20
addChild((videoNode)!)

player.play()
player.volume = 0
Run Code Online (Sandbox Code Playgroud)

非常感谢!

Mr_*_*r_P 5

最后通过解决方法到达那里:

// fix to rotate vertical video by 90 degrees and resize to fit....
videoNode?.zRotation = CGFloat(-Double.pi) * 90 / 180
videoNode?.size.width = self.frame.size.height
videoNode?.size.height = self.frame.size.width
Run Code Online (Sandbox Code Playgroud)