今天带来的是图片点击放大效果,这种效果一般在微博,微信朋友圈中比较常见
当我点击其中一张图片时,就会进入详情
具体实现如下
首先创建个 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
相关文章:
linux top下的 minerd 木马清除方法
合肥制作网站的公司有哪些,合肥聚美网络科技有限公司介绍?
高防服务器租用如何选择配置与防御等级?
制作门户网站的参考文献在哪,小说网站怎么建立?
如何快速辨别茅台真假?关键步骤解析
网站制作模板下载什么软件,ppt模板免费下载网站?
微信h5制作网站有哪些,免费微信H5页面制作工具?
视频网站制作教程,怎么样制作优酷网的小视频?
公司门户网站制作流程,华为官网怎么做?
建站10G流量真的够用吗?如何应对访问高峰?
如何正确下载安装西数主机建站助手?
高性能网站服务器部署指南:稳定运行与安全配置优化方案
建站与域名管理如何高效结合?
广州顶尖建站服务:企业官网建设与SEO优化一体化方案
建站主机SSH密钥生成步骤及常见问题解答?
文字头像制作网站推荐软件,醒图能自动配文字吗?
如何在西部数码注册域名并快速搭建网站?
极客网站有哪些,DoNews、36氪、爱范儿、虎嗅、雷锋网、极客公园这些互联网媒体网站有什么差异?
html制作网站的步骤有哪些,iapp如何添加网页?
已有域名建站全流程解析:网站搭建步骤与建站工具选择
如何用好域名打造高点击率的自主建站?
建站主机功能解析:服务器选择与快速搭建指南
建站之星后台密码如何安全设置与找回?
想学网站制作怎么学,建立一个网站要花费多少?
如何在阿里云ECS服务器部署织梦CMS网站?
山东云建站价格为何差异显著?
h5在线制作网站电脑版下载,h5网页制作软件?
美食网站链接制作教程视频,哪个教做美食的网站比较专业点?
购物网站制作费用多少,开办网上购物网站,需要办理哪些手续?
购物网站制作公司有哪些,哪个购物网站比较好?
黑客入侵网站服务器的常见手法有哪些?
韩国代理服务器如何选?解析IP设置技巧与跨境访问优化指南
宝塔新建站点报错如何解决?
已有域名和空间如何搭建网站?
建站主机是否属于云主机类型?
css网站制作参考文献有哪些,易聊怎么注册?
如何通过服务器快速搭建网站?完整步骤解析
如何用5美元大硬盘VPS安全高效搭建个人网站?
小米网站链接制作教程,请问miui新增网页链接调用服务有什么用啊?
如何在自有机房高效搭建专业网站?
,怎么用自己头像做动态表情包?
微网站制作教程,不会写代码,不会编程,怎么样建自己的网站?
c# 在ASP.NET Core中管理和取消后台任务
北京制作网站的公司排名,北京三快科技有限公司是做什么?北京三快科技?
如何基于PHP生成高效IDC网络公司建站源码?
北京网站制作的公司有哪些,北京白云观官方网站?
胶州企业网站制作公司,青岛石头网络科技有限公司怎么样?
建站VPS选购需注意哪些关键参数?
网站制作说明怎么写,简述网页设计的流程并说明原因?
音乐网站服务器如何优化API响应速度?
*请认真填写需求信息,我们会在24小时内与您取得联系。