I have a grid of UIViews that each have a touch event attached. When a UIView is touched I would like to fade all of its siblings.
Does anyone have any direction to give on this? Can the fading siblings be handled by the UIView that was touched or should the view controller fade the siblings?
EDIT: Figured it out:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for (UIView *subview in [self.superview subviews]) {
if ( subview != self ) {
subview.layer.opacity = 0.5;
}
}
[super bringSubviewToFront:self];
}
You can also do it at the UIView level. Just wrap your change to the view’s alpha inside a UIView animation block. Like this:
This should fade all subviews to half opacity over a half second. You got it sorted, but I just thought I would throw in the UIView way of achieving the same result.
Best regards.