2015-09-03 7 views
8

Uygulamamda uiview.So üzerinde bulanıklık efekti uygulamak istiyorum. kod aşağıda tarafından yargılanması: Bu kodu kullanarakiOS'ta UIView'de Nasıl Etki Bulanıklaştırılır?

UIGraphicsBeginImageContext(scrollview.bounds.size); 
[scrollview.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

//Blur the UIImage with a CIFilter 
CIImage *imageToBlur = [CIImage imageWithCGImage:viewImage.CGImage]; 
CIFilter *gaussianBlurFilter = [CIFilter filterWithName: @"CIGaussianBlur"]; 
[gaussianBlurFilter setValue:imageToBlur forKey: @"inputImage"]; 
[gaussianBlurFilter setValue:[NSNumber numberWithFloat:3] forKey: @"inputRadius"]; 
CIImage *resultImage = [gaussianBlurFilter valueForKey: @"outputImage"]; 
UIImage *endImage = [[UIImage alloc] initWithCIImage:resultImage]; 

//Place the UIImage in a UIImageView 
UIImageView *newView = [[UIImageView alloc] initWithFrame:scrollview.bounds]; 
newView.image = endImage; 
[scrollview addSubview:newView]; 

Ama sahip soruna. Bulanıklık uygulandığında zaman görünümü küçük oldu.

cevap

11

Bu bulanık görünümünü, bulanıklaştırmak istediğiniz Görünüm'e (burada yourBlurredView) koyun.

UIVisualEffect *blurEffect; 
blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]; 

UIVisualEffectView *visualEffectView; 
visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect]; 

visualEffectView.frame = yourBlurredView.bounds; 
[yourBlurredView addSubview:visualEffectView]; 

ve Swift:

var visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .Light))  

visualEffectView.frame = yourBlurredView.bounds 

yourBlurredView.addSubview(visualEffectView) 
İşte Objective-C örneğidir
İlgili konular