iOS 7 dynamic blur effect like in Control Center

前端 未结 6 2072
Happy的楠姐
Happy的楠姐 2020-12-12 11:04

I\'m trying to make a controller that will be similar to Control Center in iOS7. From WWDC session #226 I\'ve learnt how to get blurred image with different effects

6条回答
  •  感动是毒
    2020-12-12 11:40

    Here are ready solutions that I've found:

    1. The most unexpected: Use UIToolBar

    - (id) initWithFrame:(CGRect)frame
    {
        if ((self = [super initWithFrame:frame]))
        {
            [self setup];
        }
        return self;
    }
    
    - (id) initWithCoder:(NSCoder *)coder
    {
        if ((self = [super initWithCoder:coder]))
        {
            [self setup];
        }
        return self;
    }
    
    - (void) setup
    {
        if (iOS7OrLater)
        {
            self.opaque = NO;
            self.backgroundColor = [UIColor clearColor];
    
            UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:self.bounds];
            toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
            toolbar.barTintColor = self.tintColor;
            [self insertSubview:toolbar atIndex:0];
        }
    }
    

    UIToolbar can be used for this needs, bacuse it has his only build-in blur mechanism, and this mechanism is dynamic, what is good. But the bad thing is that in some reason it ignores colors and makes background looks irredeemably...

    Toolbar effect

    Update:

    To avoid color breaking, do not use barTintColor. You also may change style of toolbar if you want dark styled blur (use UIBarStyleBlack).

    2. FXBlurView.

    Unlike toolbar it more positive, but it's dynamic mechanism is rare yet and in fact it can be used only for static background. (dynamic = NO).

    FBBlurView effect

提交回复
热议问题