Full Screen preview for IOS single image, full screen ios Preview
If you are tired, it is because you are on the uphill .. This sentence seems a bit reasonable. I often remind myself not to forget why I set out wherever I went. Sometimes you can record something and record it. This time you want to write a question about clicking full screen preview on a single image, some of the functions written by some experts on the Internet are really powerful, but what you want for the time being is just a simple function, and some methods have not achieved the desired effect, at last, I wrote a simple full-screen preview and double-finger pinch zoom-in for clicking a single image. Sometimes I have to do some processing on the image. Here, I only show that the same image is not processed, paste the code below
1 // 2 // ViewController. m 3 // XWZoomImageView 4 // 5 // Created by xiao on 15/11/13. 6 // Copyright©2015 xiao. all rights reserved. 7 // 8 9 # import "ViewController. h "10 11 @ interface ViewController () <UIScrollViewDelegate> 12 @ property (weak, nonatomic) IBOutlet UIImageView * picView; 13 @ property (weak, nonatomic) UIScrollView * scrollView; 14 @ property (weak, nonatomic) UIImageView * lastImageView; 15 @ property (nonatomic, assign) CGRect originalFrame; 16 @ property (nonatomic, assign) BOOL isDoubleTap; 17 @ end18 19 @ implementation ViewController20 21-(void) viewDidLoad {22 [super viewDidLoad]; 23 24 self. picView. userInteractionEnabled = YES; 25 // Add a click gesture 26 ← * tap = [[UITapGestureRecognizer alloc] initWithTarget: self action: @ selector (showZoomImageView :)]; 27 28 [self. picView addGestureRecognizer: tap]; 29 30} 31 32-(void) showZoomImageView :( UITapGestureRecognizer *) tap33 {34 if (! [(UIImageView *) tap. view image]) {35 return; 36} 37 // scrollView as background 38 UIScrollView * bgView = [[UIScrollView alloc] init]; 39 bgView. frame = [UIScreen mainScreen]. bounds; 40 bgView. backgroundColor = [UIColor blackColor]; 41 bytes * tapBg = [[financialloc] initWithTarget: self action: @ selector (tapBgView :)]; 42 [bgView addGestureRecognizer: tapBg]; 43 44 UIImageView * picView = (UIImageView *) tap. view; 45 46 UIImageView * imageView = [[UIImageView alloc] init]; 47 imageView. image = picView. image; 48 imageView. frame = [bgView convertRect: picView. frame fromView: self. view]; 49 [bgView addSubview: imageView]; 50 51 [[[UIApplication sharedApplication] keyWindow] addSubview: bgView]; 52 53 self. lastImageView = imageView; 54 self. originalFrame = imageView. frame; 55 self. scrollView = bgView; 56 // The maximum magnification is 57 self. scrollView. maximumZoomScale = 1.5; 58 self. scrollView. delegate = self; 59 60 [UIView animateWithDuration: 0.5 animations: ^ {61 CGRect frame = imageView. frame; 62 frame. size. width = bgView. frame. size. width; 63 frame. size. height = frame. size. width * (imageView. image. size. height/imageView. image. size. width); 64 frame. origin. x = 0; 65 frame. origin. y = (bgView. frame. size. height-frame. size. height) * 0.5; 66 imageView. frame = frame; 67}]; 68} 69 70-(void) tapBgView :( UITapGestureRecognizer *) tapBgRecognizer71 {72 self. scrollView. contentOffset = CGPointZero; 73 [UIView animateWithDuration: 0.5 animations: ^ {74 self. lastImageView. frame = self. originalFrame; 75 tapBgRecognizer. view. backgroundColor = [UIColor clearColor]; 76} completion: ^ (BOOL finished) {77 [tapBgRecognizer. view removeFromSuperview]; 78 self. scrollView = nil; 79 self. lastImageView = nil; 80}]; 81} 82 83 // return a scalable view 84-(UIView *) viewForZoomingInScrollView :( UIScrollView *) scrollView85 {86 return self. lastImageView; 87}
At last, bring an image, which is roughly like this.