ios - 淡出 UICollectionView 中的项目

标签 ios objective-c cocoa-touch uikit uicollectionview

我有一个 UICollectionView,我正在按照此链接实现粘性 header :http://blog.radi.ws/post/32905838158/sticky-headers-for-uicollectionview-using#notes

它的效果非常好,但是我的窗口应用了背景图像,而我的标题 View 具有透明背景。因此,当我的项目滚动到标题 View 上方时,您仍然可以看到它们。

理想情况下,我会用渐变淡出单元格,直到它出现在标题 View 后面时才看不见。

谢谢。

最佳答案

您还没有发布任何代码,所以这里是一个不看代码的尝试。只需在您的 UICollectionView 的 super View 上设置一个 mask 层,您就可以开始了:

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;

要使此解决方案正常工作,您必须将 Collection View 嵌入到它自己的 super View 中。

有关图层蒙版的更多信息,请查看 the documentation.

关于ios - 淡出 UICollectionView 中的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24491250/

相关文章:

ios - 在模拟器中运行 Apple Watch glance 应用程序时出现问题

ios - 插入多个字符时关闭文本字段

objective-c - 在 ARC 下,如何释放 NSArray 中的元素?

objective-c - UINavigationItem 不显示事件指示器

iphone - 无法使用 UITextView 退出 FirstResponder

iphone - iPhone应用程序:如何使用MPMoviePlayerController在应用程序中播放Youtube视频

ios - AudioKit:根据陀螺仪数据/摇摆手机改变声音?

objective-c - Objective C,实现聊天应用程序的最佳方式(套接字)

objective-c - 来自字符串的 UIControlEvents 变量

xcode - 是否有关于 Interface Builder 的易于理解的指南(Cocoa、Xcode 等的新内容)谈论代理对象?