2015-09-03 6 views
8

मेरे आवेदन में मैं uiview पर धुंध प्रभाव लागू करना चाहता हूं। तो मैं धुंध प्रभाव कैसे प्राप्त कर सकता हूं। मैं कोड के नीचे से करने की कोशिश की: इस कोड का उपयोगआईओएस में UIView पर ब्लर प्रभाव कैसे लागू करें?

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]; 

लेकिन होने समस्या। जब धुंध प्रभाव लागू होता है तो समय दृश्य छोटा हो जाता है।

उत्तर

2

यदि आप आईओएस 8 या बाद में काम कर रहे हैं, तो का उपयोग UIBlurEffect के साथ करने का प्रयास करें।

11

बस इस धुंध दृश्य को देखें (यहां अपना ब्लूरेड व्यू) जिसे आप धुंधला करना चाहते हैं।

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

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

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

और स्विफ्ट:

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

visualEffectView.frame = yourBlurredView.bounds 

yourBlurredView.addSubview(visualEffectView) 
यहाँ ऑब्जेक्टिव-सी में एक उदाहरण है
संबंधित मुद्दे