CooperRS / RMPickerViewController

This is an iOS control for selecting something using UIPickerView in an UIAlertController like manner
MIT License
381 stars 51 forks source link

Option to blur UIViewController background #34

Closed jyounus closed 9 years ago

jyounus commented 9 years ago

Hey,

What would be the best way to implement blur? Not the blur effect on the Action Sheet, but instead a blur effect for the View Controller that's still visible behind it all. I want to lightly blur the content behind my View Controller when I show the action picker.

CooperRS commented 9 years ago

You mean like this?

ios simulator screen shot 07 06 2015 13 19 22

Actually it's pretty easy to get something like that. You just have to subclass RMActionController, make the property backgroundView publicly available and overwrite the getter for this property. The getter may look like follows:

- (UIView *)backgroundView {
    if(!_backgroundView) {
        UIVisualEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
        UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
        self.backgroundView = effectView;

        _backgroundView.translatesAutoresizingMaskIntoConstraints = NO;

        UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backgroundViewTapped:)];
        [_backgroundView addGestureRecognizer:tapRecognizer];
    }

    return _backgroundView;
}

If that's what you want, I'm also thinking about integrating this functionality into RMActionController. Seems to be a good idea :)...

Update: Added the option to the RMActionController git Repo

jyounus commented 9 years ago

I was thinking of a blur where you have more control over the blur amount. Something more like a custom gaussian blur with a radius you can change.

I implemented something but not into your library. I just show a blurred view before showing the picker and hide it on dismiss. I use a library called "FXBlurView" for it.

Thanks for your help tho. What you've done will probably be useful for other users in the future I guess. :)