gpt4 book ai didi

ios - 如何在滚动 Swift 时设置 UICollectionView 层不移动/静态

转载 作者:搜寻专家 更新时间:2023-10-31 22:46:38 25 4
gpt4 key购买 nike

我给 UICollectionView 添加了一个渐变层,但是这个层被设置为屏幕的宽度。我试图在滚动时保持图层静态但找不到解决方案。尝试设置为 collectionView 的框架和 currentVC,当我滚动图层时也在滚动。到目前为止,这是我的代码,感谢您的帮助。

let gradinatLayer = CAGradientLayer()
gradinatLayer.frame = self.collectionView.frame //self.currentViewController.view.frame

let cgColors:[CGColorRef] = [UIColor.blackColor().colorWithAlphaComponent(0.7).CGColor, UIColor.clearColor().CGColor, UIColor.blackColor().colorWithAlphaComponent(0.7).CGColor]

gradinatLayer.colors = cgColors
gradinatLayer.startPoint = CGPointMake(0, 0.5)
gradinatLayer.endPoint = CGPointMake(1.0, 0.5)
gradinatLayer.locations = [0.15, 0.50, 0.85]

self.collectionView.layer.insertSublayer(gradinatLayer, atIndex: 0)

//This doesn't work
self.collectionView.layer.shouldRasterize = true
self.collectionView.layer.rasterizationScale = UIScreen.mainScreen().scale

最佳答案

感谢您的所有评论。这是我深入研究 UIView 后的解决方案。不幸的是,向 UICollectionView 添加 super viewssubviews 仍然保持 View 可滚动。感谢John Stephen ,他展示了如何使用 userIntaractions 及其 subview 创建透明的 UIView,这是可能的。

我在 collectionView 上声明了一个 @IBOutlet weak var passThroughView: PassThroughView!

这是现在有效的代码:

let gradinatLayer = CAGradientLayer()
gradinatLayer.frame = self.currentViewController.view.frame

let cgColors:[CGColorRef] = [UIColor.blackColor().colorWithAlphaComponent(0.7).CGColor, UIColor.clearColor().CGColor, UIColor.blackColor().colorWithAlphaComponent(0.7).CGColor]

gradinatLayer.colors = cgColors
gradinatLayer.startPoint = CGPointMake(0, 0.5)
gradinatLayer.endPoint = CGPointMake(1.0, 0.5)
gradinatLayer.locations = [0.15, 0.50, 0.85]

passThroughView.layer.insertSublayer(gradinatLayer, atIndex: 0)

关于ios - 如何在滚动 Swift 时设置 UICollectionView 层不移动/静态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36957605/

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