ios - 当粒子发射器在屏幕上时无法单击 UIButton

标签 ios swift xcode particles emitter

使用粒子发射器时,无论位置如何,我都无法单击 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.

最佳答案

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

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

关于ios - 当粒子发射器在屏幕上时无法单击 UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64147977/

相关文章:

iOS 应用程序未显示在 App Store 中的 "New"类别下

ios - 将 Objective C 代码块转换为 Swift 闭包

xcode - SKProductsRequest 在 UI 测试和 SKTestSession 中的 Xcode 12 GM 中失败

ios - ivar 有两种不同的行为方式,但用法相同

php - 使用 MySQL 结果更改 UITextField(xcode 项目)

ios - 以编程方式使用布局 anchor 的自动布局不起作用

ios - objective-c :是否可以按一个类别拦截所有用户操作?

ios - 这是 iOS 的哪个 UI 元素?

swift - 如何为 swift 字典实现观察者模式

ios - Mapkit,如何将注释坐标更改为最近的地址?