iOS 8 模糊视图(毛玻璃效果)的简单实现UIVisualEffectView

在须要模糊的UIView上。加入一个UIVisualEffectView对象就可以。

效果例如以下图:




代码例如以下:


    UIImageView *imageview = [[UIImageViewalloc] init];

    imageview.frame =CGRectMake(10,100, 300, 300);

    imageview.image = [UIImageimageNamed:@"2"];

    imageview.contentMode =UIViewContentModeScaleAspectFit;

    imageview.userInteractionEnabled =YES;

    [self.viewaddSubview:imageview];

    

    UIBlurEffect *blur = [UIBlurEffecteffectWithStyle:UIBlurEffectStyleLight];

    UIVisualEffectView *effectview = [[UIVisualEffectViewalloc] initWithEffect:blur];

    effectview.frame =CGRectMake(0,0, imageview.size.width/2,300);

    

    [imageviewaddSubview:effectview];

    

    

    UIButton *btn = [UIButtonbuttonWithType:UIButtonTypeSystem];

    btn.frame =CGRectMake(10,50, 100, 40);

    [btn setTitle:@"btn"forState:UIControlStateNormal];

    [effectview.contentViewaddSubview:btn];



iOS开发交流群361513739

posted on 2016-02-25 16:45  gcczhongduan  阅读(184)  评论(0编辑  收藏  举报