1.添加系统高斯模糊
UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"IMG_0004"]]; imageView.frame = CGRectMake(0, 0,320, 720); [self.view addSubview:imageView]; //ios8下添加高斯模糊,模糊有3种类型 UIVisualEffectView *effectView = [[UIVisualEffectView alloc]initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]]; effectView.frame = CGRectMake(0, 100, 320, 100); [imageView addSubview:effectView]; // UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem]; btn.frame = CGRectMake(10, 50, 100, 40); btn.backgroundColor = [UIColor cyanColor]; [btn setTitle:@"btn" forState:UIControlStateNormal]; [effectView.contentView addSubview:btn];
2.添加定制高斯模糊
//高斯模糊 CIContext *context = [CIContext contextWithOptions:nil]; CIImage *inputImage = [[CIImage alloc] initWithImage:[UIImage imageNamed:@"56.jpg"]]; // create gaussian blur filter CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"]; [filter setValue:inputImage forKey:kCIInputImageKey]; [filter setValue:[NSNumber numberWithFloat:10.0] forKey:@"inputRadius"]; // blur image CIImage *result = [filter valueForKey:kCIOutputImageKey]; CGImageRef cgImage = [context createCGImage:result fromRect:[result extent]]; UIImage *image = [UIImage imageWithCGImage:cgImage]; CGImageRelease(cgImage); self.imageView.image = image;
3.创建快照
UIImageView *showView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; showView.image = [UIImage imageNamed:@"IMG_0003"]; [self.view addSubview:showView]; // 截取的view,设置NO透明度为0,Yes透明度为1 UIView *snap1 = [showView snapshotViewAfterScreenUpdates:NO]; snap1.center = self.view.center; [self.view addSubview:snap1]; NSLog(@"alpha=%f",snap1.alpha);