HeaderView.h
////HeaderView.h//Imitation Bread Travel Personal Center////Created by [e-mail protected] on 15/5/14.//Copyright (c) 2015 wb145230. All rights reserved.//#import<UIKit/UIKit.h>@interfaceHeaderview:uiview@property (nonatomic, strong) Uiscrollview*Imagescrollview, @property (nonatomic, strong) Uiimageview*imageview;//Background Image@property (nonatomic, strong) Uiimageview *imagebackgroundview;//to change the background picture/** * Change the size of the top view and the Gaussian effect * * @param offset ScrollView sliding record*/-(void) Updateheaderview: (cgpoint) offset;@end
headerview.m
////headerview.m//Imitation Bread Travel Personal Center////Created by [e-mail protected] on 15/5/14.//Copyright (c) 2015 wb145230. All rights reserved.//#import "HeaderView.h"#import<Accelerate/Accelerate.h>@implementationHeaderview-(Instancetype) initWithFrame: (CGRect) Frame {if(self =[Super Initwithframe:frame]) {Self.imagescrollview=[[Uiscrollview alloc] initWithFrame:self.bounds]; [Self addSubview:self.imageScrollView]; UIImage*image = [UIImage imagenamed:@"HEADER_BG"]; //Gaussian background imageSelf.imagebackgroundview =[[Uiimageview alloc] initWithFrame:self.imageScrollView.bounds]; [Self setblurryimage:image]; Self.imageBackgroundView.autoresizingMask= Uiviewautoresizingflexibleleftmargin | Uiviewautoresizingflexiblerightmargin | Uiviewautoresizingflexibletopmargin | Uiviewautoresizingflexiblebottommargin | Uiviewautoresizingflexibleheight |Uiviewautoresizingflexiblewidth; Self.imageBackgroundView.contentMode=Uiviewcontentmodescaleaspectfill; [Self.imagescrollview AddSubview:self.imageBackgroundView]; //OriginalSelf.imageview =[[Uiimageview alloc] initWithFrame:self.imageScrollView.bounds]; Self.imageView.image=image; Self.imageView.autoresizingMask= Uiviewautoresizingflexibleleftmargin | Uiviewautoresizingflexiblerightmargin | Uiviewautoresizingflexibletopmargin | Uiviewautoresizingflexiblebottommargin | Uiviewautoresizingflexibleheight |Uiviewautoresizingflexiblewidth; Self.imageView.contentMode=Uiviewcontentmodescaleaspectfill; [Self.imagescrollview AddSubview:self.imageView]; } returnSelf ;}/** * Change the size and Gaussian effect of the top view by sliding the scrollview * * @param offset ScrollView falling distance*/-(void) Updateheaderview: (cgpoint) offset {if(Offset.y <0) {CGRect rect= CGRectMake (0,0, Self.frame.size.width, self.frame.size.height); CGFloat Delta= Fabs (MIN (0.0f, Offset.y)); RECT.ORIGIN.Y-=Delta; Rect.size.height+=Delta; Self.imageScrollView.frame=rect; Self.clipstobounds=NO; Self.imageView.alpha= Fabs (Offset.y/(2* Cgrectgetheight (Self.bounds)/3)); }}/** * Gaussian picture * * @param originalimage need Gauss's picture*/- (void) Setblurryimage: (UIImage *) originalimage {dispatch_async (Dispatch_get_global_queue (Dispatch_queue_priority_default,0), ^{UIImage*blurredimage = [Self blurryimage:originalimage withblurlevel:0.9]; Dispatch_async (Dispatch_get_main_queue (),^{Self.imageView.alpha=0.0; Self.imageBackgroundView.image=Blurredimage; }); }); }/** * Gaussian background * * @param image requires Gaussian blur picture * @param blur Gaussian Blur value * * @return*/-(UIImage *) Blurryimage: (UIImage *) Image withblurlevel: (CGFloat) Blur {if((Blur <0.0f) || (Blur >1.0f) ) {Blur=0.5f; } intBoxsize = (int) (Blur * -); Boxsize-= (boxsize%2) +1; Cgimageref img=image. Cgimage; Vimage_buffer Inbuffer, Outbuffer; Vimage_error Error; void*Pixelbuffer; Cgdataproviderref Inprovider=Cgimagegetdataprovider (IMG); Cfdataref Inbitmapdata=Cgdataprovidercopydata (Inprovider); Inbuffer.width=cgimagegetwidth (IMG); Inbuffer.height=cgimagegetheight (IMG); Inbuffer.rowbytes=Cgimagegetbytesperrow (IMG); Inbuffer.data= (void*) cfdatagetbyteptr (inbitmapdata); Pixelbuffer= malloc (Cgimagegetbytesperrow (IMG) *cgimagegetheight (IMG)); Outbuffer.data=Pixelbuffer; Outbuffer.width=cgimagegetwidth (IMG); Outbuffer.height=cgimagegetheight (IMG); Outbuffer.rowbytes=Cgimagegetbytesperrow (IMG); Error= vimageboxconvolve_argb8888 (&inbuffer, &outbuffer, NULL,0,0, Boxsize, Boxsize, NULL, kvimageedgeextend); if(Error) {NSLog (@"error from convolution%ld", error); } cgcolorspaceref colorspace=Cgcolorspacecreatedevicergb (); Cgcontextref CTX= Cgbitmapcontextcreate (Outbuffer.data, Outbuffer.width, Outbuffer.height,8, Outbuffer.rowbytes, ColorSpace, Cgimagegetbitmapinfo (image. Cgimage)); Cgimageref Imageref=cgbitmapcontextcreateimage (CTX); UIImage*returnimage =[UIImage Imagewithcgimage:imageref]; // Clean Upcgcontextrelease (CTX); Cgcolorspacerelease (ColorSpace); Free (pixelbuffer); Cfrelease (Inbitmapdata); Cgcolorspacerelease (ColorSpace); Cgimagerelease (IMAGEREF); returnreturnimage;}@end
ViewController.h
////ViewController.h//Imitation Bread Travel Personal Center////Created by [e-mail protected] on 15/5/14.//Copyright (c) 2015 wb145230. All rights reserved.//#import<UIKit/UIKit.h>#import "HeaderView.h"@interfaceViewcontroller:uiviewcontroller<uitableviewdatasource, uitableviewdelegate>@property (nonatomic, strong) UITableView*TableView, @property (nonatomic, strong) Headerview*Headerview;@end
Viewcontroller.m
////VIEWCONTROLLER.M//Imitation Bread Travel Personal Center////Created by [e-mail protected] on 15/5/14.//Copyright (c) 2015 wb145230. All rights reserved.//#import "ViewController.h"@interfaceViewcontroller ()@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; [[UIApplication sharedapplication] setstatusbarstyle:uistatusbarstylelightcontent Animated:YES]; Self.view.backgroundColor=[Uicolor Whitecolor]; Self.tableview=[[UITableView alloc] InitWithFrame:self.view.bounds Style:uitableviewstyleplain]; Self.tableView.dataSource=Self ; Self.tableview.Delegate=Self ; Self.tableView.autoresizingMask= Uiviewautoresizingflexibleheight |Uiviewautoresizingflexiblewidth; Self.tableView.separatorColor=[Uicolor Clearcolor]; Self.tableView.showsVerticalScrollIndicator=NO; Self.headerview= [[Headerview alloc] Initwithframe:cgrectmake (0,0, Self.view.frame.size.width, -)]; Self.tableView.tableHeaderView=Self.headerview; [Self.view AddSubview:self.tableView]; }-(void) Scrollviewdidscroll: (Uiscrollview *) ScrollView {[Self.headerview updateHeaderView:scrollView.contentOffset];}-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section {return Ten;}-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{UITableViewCell*cell = [TableView dequeuereusablecellwithidentifier:@"Cell"]; if(Cell = =Nil) {Cell= [[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault reuseidentifier:@"Cell"]; } Cell.selectionstyle=Uitableviewcellselectionstylenone; returncell;}- (void) didreceivememorywarning {[Super didreceivememorywarning];}@end
Effect
If you do not see this article in the wb145230 Blog Park, please click here to view the original.
Imitation Bread Travel Personal Center dropdown top background amplification Gaussian blur effect