IOS development and ios development tutorial
Effect display
Objective-C code implementation
# Import "ViewController. h "@ interface ViewController () {// implement the fuzzy effect class uivisual1_tview * _ visual1_tview;} @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad]; [self initializeUserInterface];}-(void) initializeUserInterface {self. view. backgroundColor = [UIColor whiteColor]; // Add Image view UIImageView * imageView = [[UIImageView alloc] initWithFrame: self. view. frame]; imageView. image = [[UIImage imageNamed: @ "image.png"] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal]; imageView. contentMode = UIViewContentModeScaleAspectFit; imageView. userInteractionEnabled = YES; [self. view addSubview: imageView]; // slide bar UISlider * slider = [[UISlider alloc] initWithFrame: CGRectMake (10, CGRectGetMaxY (self. view. bounds)-50, CGRectGetWidth (self. view. bounds)-20, 30)]; slider. maximumValue = 1.0; slider. minimumValue = 0.0; slider. value = 1.0; [slider addTarget: self action: @ selector (respondsToSlider :) forControlEvents: UIControlEventValueChanged]; [self. view addSubview: slider]; // implement the fuzzy effect UIBlurEffect * blur = [invalid neural twithstyle: watermark]; _ visualiztview = [[uivisualiztview alloc] initWithEffect: blur]; _ visualiztview. frame = self. view. frame; _ visualiztview. alpha = 1.0; _ visualiztview. userInteractionEnabled = YES; [imageView addSubview: _ visualiztview];} # pragma mark-event methods-(void) respondsToSlider :( UISlider *) slider {_ visualiztview. alpha = slider. value;} @ end
Swfit code implementation
Import UIKitclass ViewController: UIViewController {var visualiztview: uivisualiztview? Override func viewDidLoad () {super. viewDidLoad () self. initializeUserInterface ()} func initializeUserInterface () {// Add Image view let imageView = UIImageView (frame: self. view. frame) imageView. image = UIImage (named: "image.png") self. view. addSubview (imageView) // Add slide bar let slider = UISlider (frame: CGRectMake (10, CGRectGetMaxY (self. view. bounds)-50, CGRectGetWidth (self. view. bounds)-20, 30) slider. ma XimumValue = 1.0 slider. minimumValue = 0.0 slider. value = 1.0 slider. addTarget (self, action: Selector ("respondsToSlider:"), forControlEvents: UIControlEvents. valueChanged) self. view. addSubview (slider) // implement the blur effect. let blur = UIBlurEffect (style: UIBlurEffectStyle. light) self. visualiztview = ({let visualiztview = uivisualiztview (effect: blur) visualiztview. frame = imageView. frame visualEff EctView. userInteractionEnabled = true visualiztview. tag = 100 visualiztview. alpha = 1.0 return visualiztview}) () imageView. addSubview (self. visualiztview !)} Func respondsToSlider (sender: UISlider) {self. visualizer tview ?. Alpha = CGFloat (sender. value )}}
Copyright Disclaimer: This article is the original article of the blogger. For more information, see the original article.