需求:

点击cell上的图片.图片以原图显示出来,可以放大或缩小.再次点击图片移除图片显示原来界面.(和QQ空间看图片类似)

点击图片实现效果:

1. 自定义一个 UITableView (KDImageDetailTableView) 在方法(- (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style)里面设置代理对象手势,tableView的背景色,隐藏指示器等

- (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style

{

self = [super initWithFrame:frame style:style];

if (self) {

// Initialization code

//解决手势冲突(代理对象必须是UIScrollView类的对象)

self.panGestureRecognizer.delegate = self;

//设置代理对象

self.dataSource = self;

self.delegate = self;

//设置背景颜色

self.backgroundColor = [UIColor blackColor];

self.backgroundView = nil;

//去掉分割线

self.separatorStyle = UITableViewCellSeparatorStyleNone;

//设置横向

//1.逆时针旋转

self.transform = CGAffineTransformMakeRotation(-M_PI_2);

//2.重新设置frame

self.frame = frame;

//3.隐藏滑动指示器

self.showsHorizontalScrollIndicator = NO;

self.showsVerticalScrollIndicator = NO;

//4.设置单元格的高度

self.rowHeight = kMainScreenWidth + 20;

//开启翻页效果

self.pagingEnabled = YES;

//默认隐藏

self.alpha = 0;

self.queue = [NSOperationQueue mainQueue];

}

return self;

}

当视图的内容在屏幕上绘制的时候

- (void)drawRect:(CGRect)rect

{

[super drawRect:rect];

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.index inSection:0];

[self scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];

}

实现数据源方法和代理方法

#pragma mark - UITableView DataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

return self.dataList.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

static NSString *identifier = @"imageDetailCellId";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

self.showIndexpath = indexPath;

if (cell == nil) {

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] ;

//去掉单元格的背景颜色

cell.backgroundColor = [UIColor clearColor];

cell.backgroundView = nil;

//取消单元格的选中事件

cell.selectionStyle = UITableViewCellSelectionStyleNone;

//顺时针旋转单元格

cell.contentView.transform = CGAffineTransformMakeRotation(M_PI_2);

//--------------创建子视图------------

//1.创建小的滑动视图(主要是为了缩放)

UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(10, 0, kMainScreenWidth, kMainScreenHeight)];

//tag

scrollView.tag = 201;

//取消弹性效果

scrollView.bounces = NO;

//设置缩放比例

scrollView.minimumZoomScale = 1.0;

scrollView.maximumZoomScale = 2.0;

scrollView.delegate = self;

scrollView.backgroundColor = [UIColor clearColor];

[cell.contentView addSubview:scrollView];

//--------------创建图片---------

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kMainScreenWidth, kMainScreenHeight)];

//      CGRectMake((kMainScreenWidth - 150)/2.0, (kMainScreenHeight -150)/2.0,150 , 150)];

//设置填充方式

imageView.contentMode = UIViewContentModeScaleAspectFit;

imageView.userInteractionEnabled = YES;

UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(imageTapAction:)];

tap.numberOfTouchesRequired = 1;

tap.numberOfTapsRequired = 1;

[imageView addGestureRecognizer:tap];

//tag

imageView.tag = 2014;

[scrollView addSubview:imageView];

UIActivityIndicatorView *aIndicatorView = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

aIndicatorView.center = CGPointMake(kMainScreenWidth/2.0, kMainScreenHeight/2.0);

aIndicatorView.hidden = YES;

aIndicatorView.tag = 2015;

[cell.contentView addSubview:aIndicatorView];

}

return cell;

}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{

[self.queue cancelAllOperations];

NSString * imageUrl =self.dataList[indexPath.row];

NSURL * requestAddress  =  [[KDDataTools share] getThumbnailUrlWithPath:imageUrl size:CGSizeMake(960, 720)];

//    NSURL  * requestAddress = [NSURL URLWithString:imageUrl];

UIImageView *imageView = (UIImageView *)[cell.contentView viewWithTag:2014];

imageView.frame = CGRectMake((kMainScreenWidth - 150)/2.0, (kMainScreenHeight -150)/2.0,150 , 150);

imageView.image = [self.thumbnailDic objectForKey:@(indexPath.row)];

UIScrollView * scrollView = (UIScrollView *)[cell.contentView viewWithTag:201];

UIActivityIndicatorView * aindicatorView =(UIActivityIndicatorView *) [cell.contentView viewWithTag:2015];

[aindicatorView startAnimating];

__weak UIImageView *weakImageView = imageView;

[imageView setImageWithURL:requestAddress placeholderImage:[self.thumbnailDic objectForKey:@(indexPath.row)] options:SDWebImageRetryFailed success:^(UIImage *image) {

// 1.把高清图片现实上去

weakImageView.image = image;

// 计算图片视图的高度 height / kscreenWith = size.heiht / size.with

float height = weakImageView.image.size.height /weakImageView.image.size.width  * kMainScreenWidth;

height = MAX(height, kMainScreenHeight);

weakImageView.frame = CGRectMake(0, 0, kMainScreenWidth, height);

scrollView.contentSize = CGSizeMake(kMainScreenWidth, height);

[aindicatorView stopAnimating];

} failure:^(NSError *error) {

}];

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

[self colse];

}

- (void)colse{

[UIView animateWithDuration:.35f animations:^{

self.alpha = 0;

}];

[self performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:.35f];

}

- (void)imageTapAction:(UITapGestureRecognizer *)tap{

[self colse];

}

#pragma mark - UIGestureRecognizer Delegate

//下面的代理方法只要是YES所有的滑动手势都会响应

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer

{

return YES;

}

- (void)showInWindowFromsuperView:(UIView *)superView{

UIWindow *windown = [superView window];

[windown addSubview:self];

[UIView animateWithDuration:1 animations:^{

self.alpha = 1;

}];

}

#pragma mark - UIScrollView Delegate

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

//如果滑动的事表示图(我不在执行下面代码)

if ([scrollView isMemberOfClass:[self class]]) {

return;

}

if (scrollView.contentOffset.x == 0 || scrollView.contentOffset.x + scrollView.width >= scrollView.contentSize.width) {

} else {

//获取滑动视图里面的手势对象,并获取位置

CGPoint point = [scrollView.panGestureRecognizer locationInView:self];

int index = point.y / 340;

//固定表示图

self.contentOffset = CGPointMake(0, index *  340);

}

}

这个方法返回的控件就是需要进行缩放的控件

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView

{

UIImageView *imageView = (UIImageView *)[scrollView viewWithTag:2014];

return imageView;

}

ios cell展示可滑动的图片的更多相关文章

  1. iOS开发系列--无限循环的图片浏览器

    --UIKit之UIScrollView 概述 UIKit框架中有大量的控件供开发者使用,在iOS开发中不仅可以直接使用这些控件还可以在这些控件的基础上进行扩展打造自己的控件.在这个系列中如果每个控件 ...

  2. IOS 非常流畅的滑动tableView

    为什么要写这篇文章呢?之前写过一篇,因为手机打字不是很方便,还有之前同事用6splus 定下午茶时候,我滑动列表时候竟然误以为是安卓系统的手机.   tableview 流畅度可以用fps来测试,到6 ...

  3. ReactNative学习-滑动查看图片第三方组件react-native-swiper

    滑动查看图片第三方组件:react-native-swiper,现在的版本为:1.4.3,该版本还不支持Android. 下面介绍的是该组件的一些用法,可能总结的不完整,希望大家一起来共同完善. 官方 ...

  4. iOS开发项目实战——Swift实现图片轮播与浏览

    近期開始开发一个新的iOS应用,自己决定使用Swift.进行了几天之后,发现了一个非常严峻的问题.那就是无论是书籍,还是网络资源,关于Swift的实在是太少了,随便一搜全都是OC实现某某某功能.就算是 ...

  5. IOS的H5页面滑动不流畅的问题:

    IOS的H5页面滑动不流畅的问题: -webkit-overflow-scrolling : touch; 需要滑动的是哪块区域,就在哪里加上这段代码就OK

  6. H5+CSS3实现手指滑动切换图片

    包含3个文件:html.slider-H5.js.jquery.js(自行下载).在html中可配置滑动参数.具体代码如下: HTML代码: <!DOCTYPE HTML> <htm ...

  7. Android:使用ViewPager实现左右滑动切换图片(图上有点点)

    在以下实例的基础上加上点点 Android:使用ViewPager实现左右滑动切换图片 (简单版) 效果预览: 因为要把点点放图片上,所以修改布局为相对布局: <?xml version=&qu ...

  8. Android:使用ViewPager实现左右滑动切换图片 (简单版)

    ViewPager,它是google SDk中自带的一个附加包的一个类, 可以使视图滑动. 步骤: 1.引入android-support-v4.jar包,在主布局里加入 <android.su ...

  9. iOS WebView 加载本地资源(图片,文件等)

    https://www.cnblogs.com/dhui69/p/5596917.html iOS WebView 加载本地资源(图片,文件等) NSString *path = [[NSBundle ...

随机推荐

  1. 用SQLite查看编辑android导出的微信聊天记录

    上一篇我们已经能够完成文字版微信聊天记录导出android了,也即复制或剪切MicroMsg.db文件到电脑,以.db格式结尾的文件是数据库文件(database document),需要安装相关数据 ...

  2. LUXURY15

    A - Guess Your Way Out! Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  3. sja1000芯片can驱动程序

    应用层使用socketCan的方法:http://pan.baidu.com/s/1ntsvbb7#path=%252Floongson1%252Ftools%252Fcan 功能:对can驱动程序的 ...

  4. ubutu之jdk安装

    1.jdk下载 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 2.解压jdk- ...

  5. svn 设置post-commit后 报错svn: Can't convert string from 'UTF-8' to native encoding

    文件语言编码和系统冲突导致的错误,设置svn目录下hooks/post-commit加上: export LANG=zh_CN.GB2312 或者: export LANG=zh_CN.UTF-8

  6. SQL Server中解决死锁

    SQL Server中解决死锁的新方法介绍 数据库操作的死锁是不可避免的,本文并不打算讨论死锁如何产生,重点在于解决死锁,通过SQL Server 2005, 现在似乎有了一种新的解决办法. 将下面的 ...

  7. javaweb框架构想-自己的对象存储池-遁地龙卷风

    设计初衷: 网站在提供服务的过程中,会创建很多对象,bean,dao层的对象尤为频繁,然而这些对象是可以重复利用的.设计思路: 对象连接池ObjectPool才用单态的设计模式,自带线程,每隔一段时间 ...

  8. Promise 原理探究及其简单实现

    可移步 http://donglegend.com/2016/09/11/promise%E5%8E%9F%E7%90%86%E6%8E%A2%E7%A9%B6/ 观看 Promise是个什么玩意,大 ...

  9. 深入理解Java虚拟机之读书笔记三 内存分配策略

    一般的内存分配是指堆上的分配,但也可能经过JIT编译后被拆散为标量类型并间接地在栈上分配.对象主要分配在新生代的Eden区上,如果启动了本地线程分配缓冲,将按线程优先在TLAB上分配,少数情况下直接分 ...

  10. Oracle 分区表的新增、修改、删除、合并。普通表转分区表方法

    一. 分区表理论知识 Oracle提供了分区技术以支持VLDB(Very Large DataBase).分区表通过对分区列的判断,把分区列不同的记录,放到不同的分区中.分区完全对应用透明. Orac ...