As the title says, I am trying to give to some UIImageViews a fading out effect as they get closer and closer to any of the four edges of my UIScrollView. Since the user can dra
Swift version of Nate answer, but only for top and bottom:
let innerColor = UIColor(white: 1.0, alpha: 0.0).CGColor
let outerColor = UIColor(white: 1.0, alpha: 1.0).CGColor;
// define a vertical gradient (up/bottom edges)
let colors = [outerColor, innerColor,innerColor,outerColor]
let locations = [0.0, 0.15,0.85,1.0]
var vMaskLayer : CAGradientLayer = CAGradientLayer()// layer];
// without specifying startPoint and endPoint, we get a vertical gradient
vMaskLayer.opacity = 0.7
vMaskLayer.colors = colors;
vMaskLayer.locations = locations;
vMaskLayer.bounds = self.scrollView.bounds;
vMaskLayer.anchorPoint = CGPointZero;
// you must add the mask to the root view, not the scrollView, otherwise
// the masks will move as the user scrolls!
self.view.layer.addSublayer(vMaskLayer)