Sam*_*Sam 12 cocoa-touch objective-c uikit ios uicollectionview
我有一个UICollectionView,我正在根据这个链接实现粘性标题:http://blog.radi.ws/post/32905838158/sticky-headers-for-uicollectionview-using #notes
它工作得非常好但是我的窗口应用了背景图像,我的标题视图具有透明背景.因此,当我的项目在标题视图上方滚动时,您仍然可以看到它们.
理想情况下,我会使用渐变淡出单元格,直到它在标题视图后面出现的时间不可见.
谢谢.
duc*_*i9y 16
你没有发布任何代码,所以这里是一个没有查看代码.只需在你UICollectionView的超级视图上设置一个遮罩层,就可以了:
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = self.collectionView.superview.bounds;
gradient.colors = @[(id)[UIColor clearColor].CGColor, (id)[UIColor blackColor].CGColor];
// Here, percentage would be the percentage of the collection view
// you wish to blur from the top. This depends on the relative sizes
// of your collection view and the header.
gradient.locations = @[@0.0, @(percentage)];
self.collectionView.superview.layer.mask = gradient;
Run Code Online (Sandbox Code Playgroud)
要使此解决方案正常工作,您必须将集合视图嵌入到自己的超级视图中.
有关图层蒙版的更多信息,请查看文档.
我在具有这种效果的collectionview上创建了一个淡入淡出模板.也许你正在寻找类似的东西.
// This is in the UICollectionView subclass
private func addGradientMask() {
let coverView = GradientView(frame: self.bounds)
let coverLayer = coverView.layer as! CAGradientLayer
coverLayer.colors = [UIColor.whiteColor().colorWithAlphaComponent(0).CGColor, UIColor.whiteColor().CGColor, UIColor.whiteColor().colorWithAlphaComponent(0).CGColor]
coverLayer.locations = [0.0, 0.5, 1.0]
coverLayer.startPoint = CGPoint(x: 0.0, y: 0.5)
coverLayer.endPoint = CGPoint(x: 1.0, y: 0.5)
self.maskView = coverView
}
// Declare this anywhere outside the sublcass
class GradientView: UIView {
override class func layerClass() -> AnyClass {
return CAGradientLayer.self
}
}
Run Code Online (Sandbox Code Playgroud)
此外,您可以通过将其添加到collectionview子类来使其变粘(即,它将始终淡出边缘上的单元格,而不是使用集合滚动).
func scrollViewDidScroll(scrollView: UIScrollView) {
self.maskView?.frame = self.bounds
}
Run Code Online (Sandbox Code Playgroud)