Swift UICollectionviewcell徽章隐藏在视图后面
我使用a来帮助向UICollectionViewCells添加大量徽章,但无论出于何种原因,徽章本身都会保留在视图后面 然而,一旦我进入视图调试器,这就是我所看到的 这是我的收集单元的代码。我尝试了与Swift UICollectionviewcell徽章隐藏在视图后面,swift,Swift,我使用a来帮助向UICollectionViewCells添加大量徽章,但无论出于何种原因,徽章本身都会保留在视图后面 然而,一旦我进入视图调试器,这就是我所看到的 这是我的收集单元的代码。我尝试了与maskToBounds和clipToBounds相关的不同值,但均无效。以及self和contentView import UIKit import BadgeControl class cellView: UICollectionViewCell { private var upperL
maskToBounds
和clipToBounds
相关的不同值,但均无效。以及self
和contentView
import UIKit
import BadgeControl
class cellView: UICollectionViewCell {
private var upperLeftBadge: BadgeController!
override init(frame: CGRect) {
super.init(frame: frame)
roundCorners(corners: .allCorners, radius: 10)
backgroundColor = .init(hexString: "#37495b")
clipsToBounds = false
// contentView.isOpaque = true
//isOpaque = true
layer.masksToBounds = false
upperLeftBadge = BadgeController(for: self, in: .upperLeftCorner, badgeBackgroundColor: #colorLiteral(red: 0.9674351811, green: 0.2441418469, blue: 0.4023343325, alpha: 1) , badgeTextColor: UIColor.white, borderWidth: 0, badgeHeight: 20)
upperLeftBadge.addOrReplaceCurrent(with: "1", animated: true)
upperLeftBadge.animateOnlyWhenBadgeIsNotYetPresent = true
upperLeftBadge.animation = BadgeAnimations.leftRight
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
您在UICollectionViewCell类中尝试过这个吗
self.bringSubviewToFront(view: upperLeftBadge.view)
对于notes
self
是您的UICollectionViewCell
我的意思是我在cells视图上使用了此视图扩展来圆角。删除对此的引用,并通过layer.cornerRadius=10将拐角四舍五入,解决了我的问题。不太清楚为什么这会隐藏重叠视图
func roundCorners(corners: UIRectCorner, radius: CGFloat) {
let path = UIBezierPath(roundedRect: bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.cgPath
layer.mask = mask
}
你能分享一下你是如何使用cellView和collectionview的吗?我尝试复制您的代码,但没有遇到任何问题。“视图”由于“私有”保护级别而无法访问。