屏幕上显示粒子发射器时无法单击UIButton

问题描述

使用粒子发射器时,无论处于什么位置,我都无法单击UIButton。如果在viewdidload中禁用了粒子发射器功能,则可以按下UIButton(播放按钮)。

我已经尝试了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.

解决方法

self.playButton.bringSubviewToFront(self.playButton)会将按钮移到其自身的前面(没有意义)!而是这样做:

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...