淡出UICollectionView中的项目 [英] Fading out items in UICollectionView

查看:111
本文介绍了淡出UICollectionView中的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UICollectionView,我实现粘性标题为这个链接: http://blog.radi.ws/post/32905838158/sticky-headers-for-uicollectionview-using#notes

I have a UICollectionView and I'm implementing sticky headers as per this link: http://blog.radi.ws/post/32905838158/sticky-headers-for-uicollectionview-using#notes

这非常有效,但我的窗口应用了背景图像,我的标题视图有一个透明的背景。因此,当我的项目滚动到标题视图之上时,您仍然可以看到它们。

It works fantastically however my window has a background image applied, and my header views have a transparent background. Consequentially, when my items scroll above the header view, you can still see them.

理想情况下,我会用渐变淡出单元格,它出现在标题视图后面的时间。

Ideally I would fade out the cells with a gradient, to the point it is invisible by the time it appears behind the header view.

感谢。

推荐答案

所以这里是一个去看它,而不看代码。只需在的UICollectionView 的超级视图上设置一个遮罩层,你就可以去了:

You haven't posted any code, so here's a go at it without looking at code. Just setup a mask layer over your UICollectionView's superview and you're good to go:

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;

要使此解决方案正常工作,您必须将集合视图嵌入到

For this solution to work properly, you'd have to embed your collection view in a super view of its own.

有关图层蒙版的详细信息,请查看文档

For more information on layer masks, check out the documentation.

这篇关于淡出UICollectionView中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆