全网整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:400-708-3566

iOS 点击图片放大效果的实现

今天带来的是图片点击放大效果,这种效果一般在微博,微信朋友圈中比较常见

当我点击其中一张图片时,就会进入详情

具体实现如下

首先创建个 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 

这样就可以实现啦........当然这里只是单纯的实现功能,至于想要图片循环什么的还是需要根据需求自行添加..

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。


# ios  # 图片点击放大  # ios开发点击图片放大  # ios图片点击放大特效  # iOS实现点击图片放大和长按保存图片的示例  # 解决iOS11图片下拉放大出现信号栏白条的bug问题  # 利用iOS手势与scrollView代理实现图片的放大缩小  # iOS tableView实现顶部图片拉伸效果  # iOS tableview实现顶部拉伸效果  # iOS TableView头视图根据偏移量下拉缩放效果  # iOS tableView实现头部拉伸并改变导航条渐变色  # iOS应用开发中UITableView的分割线的一些设置技巧  # IOS UITableView和UITableViewCell的几种样式详细介绍  # iOS tableView实现下拉图片放大效果  # 轻拍  # 的是  # 就会  # 片时  # 当我  # 大家多多  # 就可以  # 自适应  # 四张  # 圈中  # 一张图  # CGRectMake  # initWithFrame  # alloc  # backgroundColor  # UIScrollView  # implementation  # void  # NSInteger  # imageTag 


相关文章: 企业微网站怎么做,公司网站和公众号有什么区别?  上海网站制作开发公司,上海买房比较好的网站有哪些?  如何通过老薛主机一键快速建站?  如何通过商城免费建站系统源码自定义网站主题?  如何在阿里云香港服务器快速搭建网站?  如何在IIS服务器上快速部署高效网站?  商务网站制作工程师,从哪几个方面把握电子商务网站主页和页面的特色设计?  学校免费自助建站系统:智能生成+拖拽设计+多端适配  简单实现Android验证码  制作网站公司那家好,网络公司是做什么的?  建站之星后台管理如何实现高效配置?  测试制作网站有哪些,测试性取向的权威测试或者网站?  如何制作新型网站程序文件,新型止水鱼鳞网要拆除吗?  昆明高端网站制作公司,昆明公租房申请网上登录入口?  建站之星如何保障用户数据免受黑客入侵?  微信小程序 五星评分(包括半颗星评分)实例代码  Swift中循环语句中的转移语句 break 和 continue  如何在阿里云高效完成企业建站全流程?  详解ASP.NET 生成二维码实例(采用ThoughtWorks.QRCode和QrCode.Net两种方式)  建站之家VIP精选网站模板与SEO优化教程整合指南  合肥制作网站的公司有哪些,合肥聚美网络科技有限公司介绍?  建站主机与虚拟主机有何区别?如何选择最优方案?  *服务器网站为何频现安全漏洞?  如何在Golang中使用encoding/gob序列化对象_存储和传输数据  一键网站制作软件,义乌购一件代发流程?  c# 在高并发下使用反射发射(Reflection.Emit)的性能  高防服务器租用如何选择配置与防御等级?  合肥做个网站多少钱,合肥本地有没有比较靠谱的交友平台?  南京网站制作费用,南京远驱官方网站?  高防网站服务器:DDoS防御与BGP线路的AI智能防护方案  完全自定义免费建站平台:主题模板在线生成一站式服务  广州美橙建站如何快速搭建多端合一网站?  南平网站制作公司,2025年南平市事业单位报名时间?  建站之星logo尺寸如何设置最合适?  ,有什么在线背英语单词效率比较高的网站?  css网站制作参考文献有哪些,易聊怎么注册?  如何在景安服务器上快速搭建个人网站?  番禺网站制作公司哪家值得合作,番禺图书馆新馆开放了吗?  如何通过VPS建站无需域名直接访问?  大连网站制作公司哪家好一点,大连买房网站哪个好?  香港代理服务器配置指南:高匿IP选择、跨境加速与SEO优化技巧  如何选购建站域名与空间?自助平台全解析  建站VPS能否同时实现高效与安全翻墙?  如何配置FTP站点权限与安全设置?  如何获取免费开源的自助建站系统源码?  浅析上传头像示例及其注意事项  简历在线制作网站免费,免费下载个人简历的网站是哪些?  建站之星体验版:智能建站系统+响应式设计,多端适配快速建站  网站制作公司哪里好做,成都网站制作公司哪家做得比较好,更正规?  如何在Golang中引入测试模块_Golang测试包导入与使用实践 

您的项目需求

*请认真填写需求信息,我们会在24小时内与您取得联系。