我正在使用一个名为 SAConfettiView 的 Swift 库:https://github.com/sudeepag/SAConfettiView
我想在我的 View 层次结构的顶部添加一个“confettiView”,这样它就不会被其他任何东西阻挡,但我仍然希望 UIButton、UITableViewCell 等可以选择,我该如何在代码中做到这一点?
下面是我目前使用的代码:
override func viewDidLayoutSubviews() {
// Create confetti view
confettiView = SAConfettiView(frame: self.view.bounds)
// Set colors (default colors are red, green and blue)
confettiView.colors = [UIColor(red:0.95, green:0.40, blue:0.27, alpha:1.0),
UIColor(red:1.00, green:0.78, blue:0.36, alpha:1.0),
UIColor(red:0.48, green:0.78, blue:0.64, alpha:1.0),
UIColor(red:0.30, green:0.76, blue:0.85, alpha:1.0),
UIColor(red:0.58, green:0.39, blue:0.55, alpha:1.0)]
// Set intensity (from 0 - 1, default intensity is 0.5)
confettiView.intensity = 1
// Set type
confettiView.type = .Diamond
// For custom image
// confettiView.type = .Image(UIImage(named: "diamond")!)
// Add subview
view.addSubview(confettiView)
confettiView.startConfetti()
}
最佳答案
不检查第三方代码,但如果编写得当,您至少可以使用“UIView.bringSubview(ToFront:UIView)”。
当然,如果五彩纸屑确实在您的层次结构的顶部,它是 - 意思是,它没有被阻挡。
关于swift - 添加 UIView 作为 subview 并确定它们在 Swift View 层次结构中的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40918843/