gpt4 book ai didi

ios - 添加 uiview 作为背景 View

转载 作者:行者123 更新时间:2023-11-30 12:22:17 27 4
gpt4 key购买 nike

我有以下模糊 View ,我想将其作为背景 View 。问题是它成为第一个 View ,隐藏在标签/单元格等下面。我认为 self.sendSubview(toBack:blurEffectView) 会这样做 - 你知道为什么吗? :

更新:还尝试过:self.insertSubview(blurEffectView, BelowSubview: self)

import Foundation
import UIKit

extension UIView
{
func addBlurEffect()
{
if !UIAccessibilityIsReduceTransparencyEnabled() {

self.backgroundColor = UIColor.clear
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.light)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = self.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.addSubview(blurEffectView)
self.sendSubview(toBack: blurEffectView)
} else {
self.backgroundColor = UIColor.white
}

}
}

最佳答案

事实证明,只有使用UIViewController或UItableView时才会这样。

import Foundation
import UIKit

extension UIView
{
func addBlurEffect()
{
if !UIAccessibilityIsReduceTransparencyEnabled() {

self.backgroundColor = UIColor.clear
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.light)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = self.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]

if (self is UICollectionView){
(self as! UICollectionView).backgroundView = blurEffectView
}else{
self.addSubview(blurEffectView)
self.insertSubview(blurEffectView, belowSubview: self)
}

} else {
self.backgroundColor = UIColor.white
}

}
}

关于ios - 添加 uiview 作为背景 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44651723/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com