1

I have an app that uses the back camera's output as it's background. I also have a UITableView or UIScrollView (depending on the ViewController) on top of the camera view. I want to add a top-bar menu. This menu should not have any of the content of the UITableView or UIScrollView underneath it. To make it look nice I want the UITableView and UIScrollView to fade out on a gradient ... 255 (1.0f) alpha all the way up until ~45 pixels away from reaching the top-bar menu view. I have tried many "solutions" but all of them assume that the background color you want to fade too is known, in this case the background color is actually a video (of sorts). The real question here is: is there a way with iOS to have an alpha only gradient on a view... even if the view below it is a dynamically changing image? This solution cannot include ANY image manipulation, because the "image" is actually the back camera output and processing the image will take too much time and ultimately slow down the app.

Thank you in advance for anyone willing to answer my question... if it is simply not possible please explain why and I will be willing to mark your answer as correct.

any code can be in Objective-C or Swift (Swift is preferred)

iOS 8 is the target OS in this app, so if any iOS 8 libraries can help solve this question feel free to use it.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
zrubenst
  • 931
  • 9
  • 14

2 Answers2

7

Answered previously here:

CAGradientLayer *gradient = [CAGradientLayer layer];

gradient.frame = self.tableView.superview.bounds;
gradient.colors = @[(id)[UIColor clearColor].CGColor, (id)[UIColor blackColor].CGColor, (id)[UIColor blackColor].CGColor, (id)[UIColor clearColor].CGColor];
gradient.locations = @[@0.0, @0.03, @0.97, @1.0];

self.tableView.superview.layer.mask = gradient;

For more information, check out the original link.

Community
  • 1
  • 1
duci9y
  • 4,128
  • 3
  • 26
  • 42
0

Yes, you can use a CAGradientLayer as a mask. This article goes into a bunch of examples. Let me know if you need further help after looking through these.

Ryan
  • 3,853
  • 4
  • 28
  • 32
  • Thank you for the quick reply! I have come across this article on my hunt for the answer. The problem I am having is that it uses the white color as a gradient apposed to just the alpha. The biggest issue I have with the article is that I have tried this code and it will NOT work on a view with a background of clear. – zrubenst Jul 11 '14 at 19:04