gowtham gowtham - 7 days ago 5
iOS Question

How to blur the background of a container which is half of the screen

I have a view controller which consists of a container view which is half of the screen size over an image view, which is initially hided. the container is embedded with the tableView. i have a button which on click will display the container view and on the second click it will hide.

my question is how to blur the background of the container when its content are being displayed?

- (IBAction)OnClickingIndicator:(id)sender {
[self loadView];
[self.childViewControllers[0] view].hidden = ![self.childViewControllers[0] view].hidden;

}

-(void)loadView
{
UIView *blur = [[UIView alloc]initWithFrame:CGRectMake(0,150,self.view.frame.size.width,self.view.frame.size.height/4)];

blur.backgroundColor = [UIColor colorWithRed:92/255 green:100/255 blue:139/255 alpha:0.5];

[self.view addSubview:blur];

}


i want the blur effect to happen when this view is not hidden and not to happen when view is hidden.

Real problem is at first click blur effect is happening but for the next clicks blur effect is darkening and the screen is getting dark

enter image description here

Answer

If you want above image then initialize the view out side of the method.You can initialize it in view didLoad method and set the frame in your method.

You can write in this way. in .h file add:

UIView *blur;

in .m file add:

- (void)viewDidLoad {
     UIView *blur = [[UIView alloc]init];
}

- (IBAction)OnClickingIndicator:(id)sender {
[self loadView];
[self.childViewControllers[0] view].hidden = ![self.childViewControllers[0] view].hidden;

}

-(void)loadView
{
blur.frame = CGRectMake(0,150,self.view.frame.size.width,self.view.frame.size.height/4);

blur.backgroundColor = [UIColor colorWithRed:92/255 green:100/255 blue:139/255 alpha:0.5];

[self.view addSubview:blur];

} 

It will work fine for you.Thank You

Comments