I have implemented a custom activity indicator view for my iOS apps, which works smooth. The requirement is to set the alpha of superview to 50% (or make it translucent) while the custom activity indicator is animating, and set it to normal when custom activity indicator stops. I am using following class method to add custom activity indicator to view.
+ (CustomActivityIndicatorView*)addCustomActivityIndicatorToView:(UIView *)view
{
CustomActivityIndicatorView *customActivityIndicatorView = [[CustomActivityIndicatorView alloc]init];
customActivityIndicatorView.hidesWhenStopsAnimating = NO;
[customActivityIndicatorView setFrame:CGRectMake(view.bounds.size.width/2-(customActivityIndicatorView.frame.size.width/2), view.bounds.size.height/2-(customActivityIndicatorView.frame.size.height/2), customActivityIndicatorView.frame.size.width, customActivityIndicatorView.frame.size.height)];
[view addSubview:customActivityIndicatorView];
[customActivityIndicatorView startAnimating];
return customActivityIndicatorView;
}
The problem is, when I set [view setAlpha:0.5], it sets alpha to all the subviews including the custom activity indicator. I want to fade the superview not the custom activity indicator.
Read all these links;
UIView group opacity in single view heirachy
iOS controlling UIView alpha behaviour for subviews
Also tried to set layer.shouldRasterize and the plist key for group opacity but nothing helped. Please help!