First write a class write amplification method
bigimage.h// tapimagebigandsmall//// Created by lxy on 15-4-7.// Copyright (c) 2015 Shenzhen MSD Technology Co.,ltd. All rights reserved.//#import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @interface bigimage: nsobject+ (void) ShowImage: (Uiimageview *) avatarimageview;+ (void) Hideimage: (uitapgesturerecognizer*) tap; @end
Implementation method
bigimage.m//tapimagebigandsmall////Created by Lxy on 15-4-7.//Copyright (c) 2015 Shenzhen MSD technology Co., LTD. All rights reserved.//#import "BigImage.h" @implementation bigimagestatic cgrect oldframe;+ (void) ShowImage: ( Uiimageview *) avatarimageview{UIImage *image = avatarimageview.image; UIWindow *window = [UIApplication Sharedapplication].keywindow; UIView *backgroundview = [[UIView alloc]initwithframe:cgrectmake (0, 0, [UIScreen mainscreen].bounds.size.width, [UISCR Een mainscreen].bounds.size.height)]; Oldframe = [Avatarimageview convertRect:avatarImageView.bounds Toview:window]; Backgroundview.backgroundcolor = [Uicolor blackcolor]; Backgroundview.alpha = 0; Uiimageview *imageview = [[Uiimageview alloc]initwithframe:oldframe]; Imageview.image = image; Imageview.tag = 1; [Backgroundview Addsubview:imageview]; [Window Addsubview:backgroundview]; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initwithtarget:self ACtion: @selector (hideimage:)]; [Backgroundview Addgesturerecognizer:tap]; [UIView animatewithduration:0.3 animations:^{imageview.frame=cgrectmake (0, ([UIScreen Mainscreen].bounds.size.heig Ht-image.size.height*[uiscreen mainscreen].bounds.size.width/image.size.width)/2, [UIScreen MainScreen]. Bounds.size.width, Image.size.height*[uiscreen mainscreen].bounds.size.width/image.size.width); Backgroundview.alpha = 1; } completion:^ (BOOL finished) {}]; }+ (void) Hideimage: (uitapgesturerecognizer*) tap{UIView *backgroundview = Tap.view; Uiimageview *imageview = (uiimageview*) [Tap.view viewwithtag:1]; [UIView animatewithduration:0.3 animations:^{imageview.frame = oldframe; Backgroundview.alpha = 0; } completion:^ (BOOL finished) {[Backgroundview Removefromsuperview]; }]; } @end
In the View controller
viewcontroller.m//tapimagebigandsmall////Created by Lxy on 15-4-7.//Copyright (c) 2015 Shenzhen MSD Technolog Y Co.,ltd. All rights reserved.//#import "ViewController.h" #import "BigImage.h" @interface Viewcontroller () @property (nonatomic, Strong) Uiimageview *image, @end @implementation viewcontroller-(void) viewdidload {[Super viewdidload]; Self.view.backgroundColor = [Uicolor Magentacolor]; Self.image = [[Uiimageview alloc]initwithframe:cgrectmake (100, 100, 100, 100)]; _image.image = [UIImage imagenamed:@ "Me"]; _image.userinteractionenabled = YES; [Self.view Addsubview:_image]; /** * Add gestures to images click to enlarge picture */UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initwithtarget:self Act Ion: @selector (Tapclick)]; [Self.image Addgesturerecognizer:tap]; /** * A picture revolves around a circle of circles *///[self animationstart]; }-(void) tapclick{[bigimage showimage:_image];} -(void) animationstart{UIImage *image=[uiimage Imagenamed:@ "Me"]; Calayer *flystarlayer=[calayer layer]; Flystarlayer.bounds=cgrectmake (0, 0, 20, 20); flystarlayer.contents= (ID) image. Cgimage; [Self.view.layer Addsublayer:flystarlayer]; Cakeyframeanimation *keyanimation=[cakeyframeanimation animationwithkeypath:@ "position"]; keyanimation.duration=5.0; Keyanimation.removedoncompletion=no; NSNumber *number1=[nsnumber numberwithfloat:0.0]; NSNumber *number2=[nsnumber numberwithfloat:0.2]; NSNumber *number3=[nsnumber numberwithfloat:0.8]; Keyanimation.keytimes=[nsarray Arraywithobjects:number1,number2,number3, nil]; Keyanimation.fillmode=kcafillmodeforwards; Keyanimation.repeatcount=1; Cgmutablepathref circlepath=cgpathcreatemutable (); Cgpathaddarc (Circlepath, nil, 0, 4*M_PI, 0); Keyanimation.path=circlepath; Cgpathrelease (Circlepath); [Flystarlayer addanimation:keyanimation forkey:nil];}
Click on the image to enlarge, click again to zoom out to the original place