【问题标题】:Cannot Click UIButton When Particle Emitter Is On Screen粒子发射器在屏幕上时无法单击 UIButton
【发布时间】:2020-10-01 01:42:18
【问题描述】:

使用粒子发射器时,无论位置如何,我都无法单击 UIButton。如果我在 viewdidload 中禁用粒子发射器功能,我可以按下 UIButton (playButton)。

我已经尝试过 zPosition 和bringsubviewtofront。我完全没有想法。有什么想法吗?

import Foundation
import UIKit
import SpriteKit

class HomeMenu: UIViewController {

@IBOutlet weak var playButton: UIButton!

override func viewDidLoad() {
    super.viewDidLoad()

    
    //multiple emitters = multiple functions!
    //just need to alter positions
    
    //        func bringSubviewToFront(_ view: self.playButton)
    
    particleEmitter()
    
    
    bringButtonToFront()
    
    
}

func bringButtonToFront() {
    self.playButton.bringSubviewToFront(self.playButton)
   
}

func particleEmitter() {
    let sk: SKView = SKView()
    sk.frame = view.bounds
    sk.backgroundColor = .clear
    view.addSubview(sk)

    let scene: SKScene = SKScene(size: view.bounds.size)
    scene.scaleMode = .aspectFit
    scene.backgroundColor = .clear

    let en = SKEmitterNode(fileNamed: "SparkParticle.sks")
    //position of emitter on 2d plane
    en?.position = CGPoint(x:50, y:50)

    scene.addChild(en!)
    sk.presentScene(scene)
    //zposition brought emitter to front of view to make visible
    scene.zPosition = 10
}

@IBAction func playButton(_ sender: Any) {
    performSegue(withIdentifier: "startGaneSegue", sender: self)
}


}

In the image, you can see the emitter is located at the bottom left of the screen, but the button is unclickable. Only when removing the emitter is the button clickable.

【问题讨论】:

    标签: ios swift xcode particles emitter


    【解决方案1】:

    self.playButton.bringSubviewToFront(self.playButton) 将按钮带到它自己的前面(没有意义)!改为这样做:

    func bringButtonToFront() {
        self.view.bringSubviewToFront(self.playButton)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多