IOS implementation Picture Click Full Screen preview _ios

Source: Internet
Author: User

If you feel tired, that's right because you're going uphill. This sentence seems to have a sense of appearance, often remind yourself no matter where you go, don't forget why you started. Sometimes think about feeling something that can be recorded, just record it, this time to write about a single picture Click Full-screen Preview of the problem, online check some of the great God wrote some of the functions are really strong but I want to temporarily just simple function is good, and some methods do not make the desired effect, Finally wrote a relatively simple click on a single picture of the full screen preview and double finger kneading shrink zoom, may sometimes want to do some processing of the picture, here magnified just show the same picture did not do processing, the following directly posted code

VIEWCONTROLLER.M//Xwzoomimageview////Created by Xiao on 15/11/13. Copyright©2015 year Xiao.
All rights reserved. #import "ViewController.h" @interface Viewcontroller () <UIScrollViewDelegate> @property (weak, nonatomic) Ibou
Tlet Uiimageview *picview;
@property (Weak, nonatomic) Uiscrollview *scrollview;
@property (Weak, nonatomic) Uiimageview *lastimageview;
@property (nonatomic, assign) CGRect originalframe;
@property (nonatomic, assign) BOOL Isdoubletap;
 
 @end @implementation Viewcontroller-(void) viewdidload {[Super viewdidload];
 self.picView.userInteractionEnabled = YES; Add Click gesture UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (

 Showzoomimageview:)];
 
[Self.picview Addgesturerecognizer:tap]; }-(void) Showzoomimageview: (UITapGestureRecognizer *) Tap {if (![
 (Uiimageview *) Tap.view image]) {return;
 //scrollview as background Uiscrollview *bgview = [[Uiscrollview alloc] init]; Bgview.frame = [UIScreen maInscreen].bounds;
 Bgview.backgroundcolor = [Uicolor blackcolor];
 UITapGestureRecognizer *TAPBG = [[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (Tapbgview:)];
 
 [Bgview ADDGESTURERECOGNIZER:TAPBG];
 
 Uiimageview *picview = (Uiimageview *) Tap.view;
 Uiimageview *imageview = [[Uiimageview alloc] init];
 Imageview.image = Picview.image;
 Imageview.frame = [Bgview convertRect:picView.frame FromView:self.view];
 
 [Bgview Addsubview:imageview];
 
 [[[[UIApplication sharedapplication] Keywindow] addsubview:bgview];
 Self.lastimageview = ImageView;
 Self.originalframe = Imageview.frame;
 Self.scrollview = Bgview;
 Maximum magnification ratio self.scrollView.maximumZoomScale = 1.5;
 
 Self.scrollView.delegate = self;
  [UIView animatewithduration:0.5 animations:^{cgrect frame = imageview.frame;
  Frame.size.width = BgView.frame.size.width;
  Frame.size.height = Frame.size.width * (imageview.image.size.height/imageview.image.size.width);
  frame.origin.x = 0; FRAME.ORIGIN.Y = (Bgview.frame.size.height-frame.size.height) * 0.5;
 Imageview.frame = frame;
}];
 }-(void) Tapbgview: (UITapGestureRecognizer *) Tapbgrecognizer {self.scrollView.contentOffset = Cgpointzero;
  [UIView animatewithduration:0.5 animations:^{self.lastImageView.frame = self.originalframe;
 TapBgRecognizer.view.backgroundColor = [Uicolor Clearcolor];
  } completion:^ (BOOL finished) {[Tapbgrecognizer.view Removefromsuperview];
  Self.scrollview = nil;
 Self.lastimageview = nil;
}];
 //Returns a scalable View-(UIView *) Viewforzoominginscrollview: (Uiscrollview *) ScrollView {return self.lastimageview;}

And finally, take a picture, which is roughly like this.

To share an iOS click on the image after the enlarged code

. h file-----------------------------------------------------------------#import @interface zoomimage:nsobject/** *@
Brief click the picture to enlarge, click again to zoom Out * * @param oldimageview Avatar ImageView * * + (void) ShowImage: (uiimageview*) Avatarimageview; @end. m file-----------------------------------------------------------------#import "ZoomImage.h" Static CGRect
Oldframe;
 @implementation Zoomimage + (void) ShowImage: (uiimageview*) Avatarimageview {uiimage *image;
 Get root window UIWindow *window =[uiapplication Sharedapplication].keywindow;
 UIView *backgroundview =[[uiview alloc]initwithframe:cgrectmake (0, 0, WIDTH, HEIGHT)];
 Oldframe =[avatarimageview convertRect:avatarImageView.bounds Toview:window];
 Backgroundview.backgroundcolor =[uicolor Blackcolor];
 Backgroundview.alpha = 0.5;
 Uiimageview *imageview =[[uiimageview Alloc]initwithframe:oldframe];
 Imageview.image =image;
 Imageview.tag = 1;
 [Backgroundview Addsubview:imageview];
 [Window Addsubview:backgroundview]; Click on the picture to shrink the gesture 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.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;
}];
 } + (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];
}]; }

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.