麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

IOS圖片全屏預覽

2019-11-14 17:56:08
字體:
來源:轉載
供稿:網友

  如果你感覺累,那就對了那是因為你在走上坡路。。這句話似乎有點道理的樣子,時常提醒自己無論走到哪都不要忘記自己當初為什么出發。有時想想感覺有的東西可以記錄一下,就把它記錄下來吧,這次想寫一下關于單張圖片點擊全屏預覽的問題,網上查了一些大神寫的有的功能確實很強大但自己暫時想要的只是簡單的功能就好,還有些方法自己也沒弄出想要的效果,最后寫了一個比較簡單的點擊單張圖片的全屏預覽和雙指捏合縮小放大,可能有時要對圖片做一些處理,這里放大后只是顯示同一張圖片并未做處理,下面直接貼出代碼

 1 // 2 //  ViewController.m 3 //  XWZoomImageView 4 // 5 //  Created by xiao on 15/11/11. 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 @end17 18 @implementation ViewController19 20 - (void)viewDidLoad {21     [super viewDidLoad];22     23     self.picView.userInteractionEnabled = YES;24     //添加單擊手勢25     UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showZoomImageView:)];26 27     [self.picView addGestureRecognizer:tap];28     29 }30 31 -(void)showZoomImageView:(UITapGestureRecognizer *)tap32 {33     if (![(UIImageView *)tap.view image]) {34         return;35     }36     //scrollView作為背景37     UIScrollView *bgView = [[UIScrollView alloc] init];38     bgView.frame = [UIScreen mainScreen].bounds;39     bgView.backgroundColor = [UIColor blackColor];40     UITapGestureRecognizer *tapBg = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapBgView:)];41     [bgView addGestureRecognizer:tapBg];42     43     UIImageView *picView = (UIImageView *)tap.view;44     45     UIImageView *imageView = [[UIImageView alloc] init];46     imageView.image = picView.image;47     imageView.frame = [bgView convertRect:picView.frame fromView:self.view];48     [bgView addSubview:imageView];49     50     [[[UIapplication sharedApplication] keyWindow] addSubview:bgView];51     52     self.lastImageView = imageView;53     self.originalFrame = imageView.frame;54     self.scrollView = bgView;55     //最大放大比例56     self.scrollView.maximumZoomScale = 1.5;57     self.scrollView.delegate = self;58     59     [UIView animateWithDuration:0.5 animations:^{60         CGRect frame = imageView.frame;61         frame.size.width = bgView.frame.size.width;62         frame.size.height = frame.size.width * (imageView.image.size.height / imageView.image.size.width);63         frame.origin.x = 0;64         frame.origin.y = (bgView.frame.size.height - frame.size.height) * 0.5;65         imageView.frame = frame;66     }];67 }68 69 -(void)tapBgView:(UITapGestureRecognizer *)tapBgRecognizer70 {71     self.scrollView.contentOffset = CGPointZero;72     [UIView animateWithDuration:0.5 animations:^{73         self.lastImageView.frame = self.originalFrame;74         tapBgRecognizer.view.backgroundColor = [UIColor clearColor];75     } completion:^(BOOL finished) {76         [tapBgRecognizer.view removeFromSuperview];77         self.scrollView = nil;78         self.lastImageView = nil;79     }];80 }81 82 //返回可縮放的視圖83 -(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView84 {85     return self.lastImageView;86 }

 

最后同樣帶上一張圖片吧,大致是這樣子


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 久久久tv| 麻豆自拍偷拍视频 | 99re66热这里只有精品8 | 黄色免费小视频网站 | 中文字幕在线观看视频一区 | 一区二区久久精品66国产精品 | 亚洲精品在线观看网站 | 成年免费看 | 久久精品探花 | 羞羞网站| 亚洲第一页夜 | 91精品福利视频 | 欧美一级毛片美99毛片 | 看免费一级毛片 | 视频h在线 | 欧美a∨一区二区三区久久黄 | 天堂福利电影 | 91精品国产综合久久婷婷香蕉 | 97se亚洲综合在线韩国专区福利 | 伊人999| 中文字幕在线永久视频 | 免费黄色小网站 | 精品一区二区久久久久久按摩 | 韩国一级免费视频 | av手机在线免费播放 | 国产午夜精品久久久久 | 天堂成人一区二区三区 | 伦一区二区三区中文字幕v亚洲 | 麻豆视频国产在线观看 | 国产成人自拍av | 羞羞视频.www在线观看 | 今井夏帆av一区二区 | 97超级碰碰人国产在线观看 | 午夜精品久久久久久久99热浪潮 | 亚洲第五色综合网 | 久久久午夜电影 | 久久精品国产精品亚洲 | 欧美一级片在线 | 国产精品一区二区视频 | arabxxxxvideos | 欧美精品一区二区三区在线播放 |