Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Darkening everything in UIViewController view except for a few UIImageViews

I'm working in iOS 6. Is there an easy way to darken (i.e. add a darker tint) to everything on a UIViewController screen except for a few select UIImageViews?

Like, the goal is to make the non-darkened images stand out. The user clearly knows those are the only valid or selectable UIImageViews to tap -- and when the user taps a valid UIImageView, the screen would return to normal.

Just to clarify, I don't just want to vanish everything else, just darken it, like adding a transparent 0.5 alpha layer.

I looked here: Darken view as if disabled and it seems very relevant, except I'm not working on a single UIImageView, but a UIViewController that has UIImageViews as subviews. And even if I run the masking code on every subview in my superview, it still wouldn't cover the entire screen, I think.

Thanks for your help.

like image 988
Erika Electra Avatar asked Nov 08 '13 07:11

Erika Electra


1 Answers

UIView *blackView = [[UIView alloc] initWithFrame:someFrame];
blackView.backgroundColor = [UIColor blackColor];
blackView.alpha = 0.5;
[self.view addSubview:blackView];
for (UIImageView *imageViewToShow in self.view.subviews) {
    [self.view bringSubviewToFront:imageViewToShow];
}

If this causes problems, you might consider redesigning your code to keep the images inside a containerView of sorts. Then you can simply use [self.view insertSubview:blackView belowSubview:containerView]; instead. Then you can manipulate the alpha and hidden aspects of the blackView whenever you feel like it. Heck, if your design warrants it you might add the blackView before any images have been created omitting the meed of the container view as well...

like image 133
T. Benjamin Larsen Avatar answered Nov 15 '22 09:11

T. Benjamin Larsen