Click the image to zoom in. Click it again to zoom in and zoom out.

Source: Internet
Author: User

Click the image to zoom in. Click it again to zoom in and zoom out.
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, [UIScreen 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]; optional * tap = [[using alloc] initWithTarget: self action: @ selector (hideImage :)]; [backgroundView addGestureRecognizer: tap]; [UIView animateWithDuration: 0.3 animations: ^ {imageView. frame = CGRectMake (0, ([UIScreen mainScreen]. bounds. size. height-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 View Controller

//// ViewController. m // TapImageBigAndSmall /// Created by lxy on 15-4-7. // Copyright (c) 2015 Shenzhen MSD Technology 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 a gesture to the image. Click to enlarge the image. */UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget: self action: @ selector (tapClick)]; [self. image addGestureRecognizer: tap];/*** an image is circled around a circle * // [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 limit: 0.8]; // keyAnimation. keyTimes = [NSArray arrayWithObjects: number1, number2, number3, nil]; keyAnimation. fillMode = kCAFillModeForwards; keyAnimation. repeatCount = 1; CGMutablePathRef circlePath = CGPathCreateMutable (); CGPathAddArc (circlePath, nil, 100,150, 50, 0, 4 * M_PI, 0); keyAnimation. path = circlePath; CGPathRelease (circlePath); [flyStarLayer addAnimation: keyAnimation forKey: nil];}



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.