【问题标题】:Image View is not visible on SceneKit View图像视图在 SceneKit 视图上不可见
【发布时间】:2022-01-17 00:20:19
【问题描述】:

我的图像在 Scenekit 中不可见,我还在按钮可见时进行了测试,图像按钮或带有图像背景的按钮变得不可见。有什么想法吗?

【问题讨论】:

    标签: xcode imageview scenekit


    【解决方案1】:

    我终于在 Scenekit 视图上显示了一个图像,但没有使用图像视图。我检查了 Fox2SceneKitWWDC2017 示例项目,我看到他们使用了 SpriteKit 覆盖。我使用 Fox2 示例代码来执行此操作,如下所示。万一身体需要……

    //
    //  Overlay.swift
    //  Remote
    //
    //  Created by Mustafa Akkuzu on 14.12.2021.
    //
    import Foundation
    import SceneKit
    import SpriteKit
    
    class Overlay: SKScene {
        private var overlayNode: SKNode
        
    // MARK: - Initialization
        init(size: CGSize, controller: ViewController) {
            overlayNode = SKNode()
            super.init(size: size)
            scaleMode = .resizeFill
            addChild(overlayNode)
            
            // Assign the SpriteKit overlay to the SceneKit view.
            isUserInteractionEnabled = false
        }
        
        required init?(coder aDecoder: NSCoder) {
            fatalError("init(coder:) has not been implemented")
        }
        
        func showImage() {
            // Congratulation title
            let congratulationsNode = SKSpriteNode(imageNamed: "circle.png")
            overlayNode.addChild(congratulationsNode)
    
            let w: CGFloat = size.width
            let h: CGFloat = size.height
            overlayNode.position = CGPoint(x: w/2, y: h/2)
            
            // Animate
            congratulationsNode.alpha = 0.0
            congratulationsNode.xScale = 0
            congratulationsNode.yScale = 0
            congratulationsNode.run( SKAction.group([SKAction.fadeIn(withDuration: 0.25),
                                     SKAction.sequence([SKAction.scale(to: 1.22, duration: 0.25),
                                    SKAction.scale(to: 1.0, duration: 0.1)])]))
    
        }
        
    }
    

    用法:

        let overlay = Overlay(size: sceneView.bounds.size, controller: self)
        sceneView.overlaySKScene = overlay
        overlay.showImage()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-30
      • 1970-01-01
      • 2012-09-12
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      相关资源
      最近更新 更多