2016-12-01 31 views
1

我使用所謂SAConfettiView迅捷的庫:https://github.com/sudeepag/SAConfettiView添加的UIView的爲子視圖並確定其位置在視圖層次斯威夫特

我想在我的視圖層次的頂部添加一個「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() 
} 

回答

1

不檢查了第三方的代碼,但如果它的正確寫的,你可以 - 至少是 - 使用「UIView.bringSubview(ToFront :UIView的)」。

當然,如果紙屑真正在層次結構的頂部,它是 - 的意義,這是阻礙。

+0

只是爲了確認當我說視圖層次結構的頂部時,我的意思是屏幕上最頂端的項目(我可能錯誤地說'頂部')。 –

+0

如果它在屏幕上最上方,那麼它可能會干擾觸摸,對吧?它似乎是一個UIView,它將成爲最頂層的Z層。也許你能做的最好的事情就是在你的UIButtons中添加這樣一個可以避免阻礙的UIButtons - 無論是在這個五彩紙屑UIView沒有阻擋的地方,還是作爲五彩紙屑UIView的子視圖。我想我可以說我知道你想要什麼......但你能否說你看到了一個有效的例子? – dfd

+0

它確實會干擾觸摸,我還沒有在所有其他視圖前面看到「五彩紙屑」的例子。 –

相關問題