swift - 添加 UIView 作为 subview 并确定它们在 Swift View 层次结构中的位置

标签 swift uiview

我正在使用一个名为 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/

相关文章:

ios - 如何在 iOS Swift 中向多个 ViewController 添加一个公共(public) View ?

ios - 在 Xcode/Swift 中使用预设置 View

arrays - 如何在 Swift 中访问数组的非第一个元素?

ios - 核心数据删除一个元素 NSManagedObject Swift

swift - 使用 uiTextView 关闭键盘

ios - 使用页面 Controller 将数据从 uiscrollview 传递到另一个 View Controller

ios - Pan Gesture 正在工作,但 ONTapGesture 不在 UIView 上工作

ios - 动画 UIView 形状及其内容

swift - 什么样的异常可能 String(contentsOf url :URL) throw?

swift - MKPointAnnotation 到 MKMapItem