国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS 點擊圖片放大效果的實現

2020-07-26 02:59:14
字體:
來源:轉載
供稿:網友

今天帶來的是圖片點擊放大效果,這種效果一般在微博,微信朋友圈中比較常見

當我點擊其中一張圖片時,就會進入詳情

具體實現如下

首先創建個 Controller(PhotoViewController)

// // PhotoViewController.h // 點擊圖片放大效果 // // Created by Amydom on 17/1/9. // Copyright © 2017年 Amydom. All rights reserved. //  #import <UIKit/UIKit.h>  @interface PhotoViewController : UIViewController  //保存圖片的數組 @property (nonatomic, strong)NSMutableArray *photoArr; //圖片 tag @property (nonatomic, assign)NSInteger imageTag;  @end 
// // PhotoViewController.m // 點擊圖片放大效果 // // Created by Amydom on 17/1/9. // Copyright © 2017年 Amydom. All rights reserved. //  #import "PhotoViewController.h"  @interface PhotoViewController ()  @end  @implementation PhotoViewController  - (void)viewDidLoad {   [super viewDidLoad];      UIScrollView *myScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 375, 667)];      myScrollView.backgroundColor = [UIColor blackColor];   myScrollView.pagingEnabled = YES;   myScrollView.bounces = NO;      [self.view addSubview:myScrollView];   //根據tag 來獲取當前點擊的圖片   myScrollView.contentOffset = CGPointMake(self.view.frame.size.width * self.imageTag, 10);      myScrollView.contentSize = CGSizeMake(self.view.frame.size.width * self.photoArr.count, 667);   //創建   for (int i = 0; i < self.photoArr.count; i++)   {     UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width * i + 10, 0, self.view.frame.size.width - 20, self.view.frame.size.height)];     NSString *imgName = self.photoArr[i];     img.image = [UIImage imageNamed:imgName];          [myScrollView addSubview:img];          //自適應圖片大小     img.contentMode = UIViewContentModeScaleAspectFit;        }      //輕拍跳出照片瀏覽   UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];      [myScrollView addGestureRecognizer:tap];  }  - (void)tapAction {   [self dismissViewControllerAnimated:YES completion:^{             }]; }  - (void)didReceiveMemoryWarning {   [super didReceiveMemoryWarning];   // Dispose of any resources that can be recreated. }  /* #pragma mark - Navigation  // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {   // Get the new view controller using [segue destinationViewController].   // Pass the selected object to the new view controller. } */  @end 

然后在 ViewController 中創建四張小圖片,添加輕拍手勢

// // ViewController.m // 點擊圖片放大效果 // // Created by Amydom on 17/1/9. // Copyright © 2017年 Amydom. All rights reserved. //  #import "ViewController.h" #import "PhotoViewController.h"  @interface ViewController (){      NSMutableArray *array;    }  @end  @implementation ViewController  - (void)viewDidLoad {   [super viewDidLoad];   self.view.backgroundColor = [UIColor whiteColor];   array = [NSMutableArray arrayWithObjects:@"1.jpg", @"2.jpg",@"3.jpg",@"4.jpg", nil nil];   for (int i = 0; i < array.count; i++) {          UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(20 + 880 * i, 100, 70, 70)];     img.image = [UIImage imageNamed:[array objectAtIndex:i]];          img.userInteractionEnabled = YES;          //截掉邊框     img.clipsToBounds = YES;          img.tag = 1000 + i;          UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(TapAction:)];          [img addGestureRecognizer:tap];          [self.view addSubview:img];   }  }  - (void)TapAction:(UITapGestureRecognizer *)tap{      PhotoViewController *photoVC = [[PhotoViewController alloc] init];   photoVC.imageTag = tap.view.tag - 1000 ;//獲取當前被點擊圖片的 tag   photoVC.photoArr = array;   [photoVC setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];// 效果   [self presentModalViewController:photoVC animated:YES];    } - (void)didReceiveMemoryWarning {   [super didReceiveMemoryWarning];   // Dispose of any resources that can be recreated. }   @end 

這樣就可以實現啦........當然這里只是單純的實現功能,至于想要圖片循環什么的還是需要根據需求自行添加..

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 科技| 南阳市| 连平县| 方山县| 稷山县| 姜堰市| 乌鲁木齐县| 喀喇| 平湖市| 彭州市| 宜兴市| 大埔县| 临潭县| 沁阳市| 中方县| 肥乡县| 无锡市| 莱州市| 左权县| 蓬安县| 鹤庆县| 宜章县| 兴安盟| 朝阳区| 江华| 宣恩县| 达州市| 温州市| 静海县| 虎林市| 济南市| 寿光市| 福清市| 吉安县| 台北县| 吴忠市| 应城市| 新安县| 湟中县| 耿马| 宿松县|