Analysis of iOS development & quot; secret & quot; Page effects of App content
Recently I was playing "secret" and found that clicking the Cell on the main interface has a good page effect. I wrote a Demo to demonstrate it.
Its main effect is to zoom in the drop-down header, blur the top-up view, and remain unchanged at a certain position. Other cells can move up.
@ Encapsulation main effect class: MTHeadEffect. m (. h file omitted, very simple)
# Import "MTHeadEffect. h" # import
# Import // The physical width of the screen # define ScreenWidth [UIScreen mainScreen]. bounds. size. width # define HeadViewH 40 CGFloat const direction = 200.f; @ implementation MTHeadEffect + (void) viewDidScroll :( UIScrollView *) tableView withHeadView :( UIImageView *) headView withBlur :( CGFloat) blur {NSLog (@ "y = % f", tableView. contentOffset. y); if (tableView. contentOffset. y> kImageOriginHight-HeadViewH) {headView. frame = CGRectMake (0,-(kImageOriginHight-HeadViewH), ScreenWidth, kImageOriginHight); [[UIApplication sharedApplication]. keyWindow addSubview: headView];} else if (tableView. contentOffset. y <kImageOriginHight-HeadViewH) & tableView. contentOffset. y> 0) {blur = (tableView. contentOffset. y)/500.0 + 0.45; headView. image = [[UIImage imageNamed: @ "2"] boxblurImageWithBlur: blur]; headView. frame = CGRectMake (0, 0, ScreenWidth, kImageOriginHight); [tableView addSubview: headView];} else if (tableView. contentOffset. y <= 0) {// enlarge the result --- increment and width of the x and y coordinates, and the increment of the height remains the same CGFloat offset =-tableView. contentOffset. y; headView. frame = CGRectMake (-offset,-offset, ScreenWidth + offset * 2, kImageOriginHight + offset); headView. image = [[UIImage imageNamed: @ "2"] boxblurImageWithBlur: 0.01] ;}@ end @ implementation UIImage (BlurEffect) // a category encapsulated for Gaussian blur effect-(UIImage *) boxblurImageWithBlur :( CGFloat) blur {NSData * imageData = UIImageJPEGRepresentation (self, 1 ); // convert to jpeg UIImage * destImage = [UIImage imageWithData: imageData]; if (blur <0.f | blur> 1.f) {blur = 0.5f;} int boxSize = (int) (blur * 40); boxSize = boxSize-(boxSize % 2) + 1; CGImageRef img = destImage. CGImage; vImage_Buffer inBuffer, outBuffer; vImage_Error error; void * pixelBuffer; // create vImage_Buffer with data from CGImageRef effecinprovider = encrypted (img); CFDataRef inBitmapData = encrypted (inProvider); inBuffer. width = CGImageGetWidth (img); inBuffer. height = CGImageGetHeight (img); inBuffer. rowBytes = CGImageGetBytesPerRow (img); inBuffer. data = (void *) CFDataGetBytePtr (inBitmapData); // create vImage_Buffer for output pixelBuffer = malloc (CGImageGetBytesPerRow (img) * CGImageGetHeight (img); if (pixelBuffer = NULL) NSLog (@ "No pixelbuffer"); outBuffer. data = pixelBuffer; outBuffer. width = CGImageGetWidth (img); outBuffer. height = CGImageGetHeight (img); outBuffer. rowBytes = percent (img); // Create a third buffer for intermediate processing void * percent = malloc (percent (img) * CGImageGetHeight (img); vImage_Buffer outBuffer2; outBuffer2.data = percent; outBuffer2.width = CGImageGetWidth (img); outBuffer2.height = CGImageGetHeight (img); margin = accept (img); // perform convolution error = ignore (& inBuffer, & outBuffer2, NULL, 0, 0, boxSize, boxSize, NULL, kvImageEdgeExtend); if (error) {NSLog (@ "error from convolution % ld", error);} error = vImageBoxConvolve_ARGB8888 (& outBuffer2, & inBuffer, NULL, 0, 0, boxSize, boxSize, NULL, kvImageEdgeExtend); if (error) {NSLog (@ "error from convolution % ld", error );} 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, (CGBitmapInfo) values); CGImageRef imageRef = values (ctx); UIImage * returnImage = [UIImage imageWithCGImage: imageRef]; // clean up CGContextRelease (ctx ); cgcolorspacerelshort (colorSpace); free (pixelBuffer); free (pixelBuffer2); CFRelease (inBitmapData); cgimagerelshort (imageRef); return returnImage;} @ end
@ Main. m
-(Void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. // tableView self. testTableView = [[UITableView alloc] initWithFrame: CGRectMake (0, 0,320,568) style: UITableViewStylePlain]; self. testTableView. delegate = self; self. testTableView. dataSource = self; [self. view addSubview: _ testTableView];/***** hide the status bar effect * 1. the system provides two types of Animation: Offset and fade-away. in the plist file, set "View controlle R-based status bar appearance is set to "No" */[[UIApplication sharedApplication] setStatusBarHidden: YES withAnimation: UIStatusBarAnimationNone]; // headView is not used as tableHeadView, it overwrites self on the first Cell. headView = [[UIImageView alloc] initWithFrame: CGRectMake (0, 0,320,200)]; self. headView. image = [[UIImage imageNamed: @ "2"] boxblurImageWithBlur: 0.01]; self. headView. contentMode = UIViewContentModeScaleAspectFil L; // picture display height self. headView. clipsToBounds = YES; [self. testTableView addSubview: self. headView] ;}# pragma mark-scroll delegate head view effect method-(void) scrollViewDidScroll :( UIScrollView *) scrollView {[MTHeadEffect viewDidScroll: scrollView withHeadView: self. headView withBlur: 0.01];}-(NSInteger) numberOfSectionsInTableView :( UITableView *) tableView {return 1;}-(NSInteger) tableView :( UITableView *) tableView nu MberOfRowsInSection :( NSInteger) section {return 25;}-(CGFloat) tableView :( UITableView *) tableView heightForRowAtIndexPath :( NSIndexPath *) indexPath {if (indexPath. row = 0) {return 200;} return 40;}-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {static NSString * celstmentf = @ "cell"; UITableViewCell * cell = [tableView dequeueReusableHeaderFoo TerViewWithIdentifier: celstmentf]; if (! Cell) {cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: cellIdentf];} cell. textLabel. text = [NSString stringWithFormat: @ "section = % ld row = % ld", indexPath. section, indexPath. row]; return cell ;}
@: Well, it won't make gif animations, so it's not a good demonstration. The key code has been provided. You can try it on your own.