I've made a little research about my problem and unfortunately there was no solution for my problem. The closest was Fade UIImageView as it approaches the edges of a UIScrollView but it's still not for me.
I want my table to apply an "invisibility gradient" on the top. If the cell is at a 50px distance from the top edge it starts to vanish. The closer it is to the upper edge, the more invisible the part is. The cells height is about 200 pixels, so the lower part of the cell need to be visible in 100%. But nevermind - I need a table view (or table view container) to do this task, because similar tables can display other cells.
If the table is a subview of a solid color view, I can achieve that by adding an image which is a horizontal gradient that I can streach to any width. The top pixel of that image starts with the exact color of the background, and going down the same color has less alpha.
But... we have a UITableView with transparent color. Below the table there is no solid color, but a pattern image/texture, that can also be different on other screens of the app.
Do you have any Idea how I can achieve this behaviour?
Regards
This is my version of the fading table view by inheriting UITableView. Tested for iOS 7 & 8.
CEFadingTableView.m
This is a translation of Aviel Gross's answer to Swift
I took this tutorial and made some changes and additions:
1. Start by importing
QuartzCore
and setting a mask layer in your controller:EDIT: No need for reference to
CAGradientLayer
in class.2. Add this to
viewWillAppear
viewDidLayoutSubviews
: (See @Darren's comment on this one)3. Make sure you are a delegate of
UIScrollViewDelegate
by adding it in the.h
of your controller:4. To finish, implement
scrollViewDidScroll
in your controller.m
:Again: most of the solution is from this tutorial in cocoanetics.
Swift 3 Version of @victorfigol's excellent solution: