iOS -点击按钮查看大图,再次点击还原效果(此处以UITableViewCell为父视图,其中加载多个图片为例)
2016-01-10 18:14
681 查看
#import "xxxCell.h"
#import <UIButton+WebCache.h>
staticCGRect oldframe;//用于记录放大之前的frame
@implementation xxxCell
- (void)awakeFromNib {
}
//1.给cell赋值
-(void)reDrawInfoContentView:(xxxModel*)model{
CGRect aRect, bRect, bounds =
CGRectMake(10, height +
25, self.contentView.bounds.size.width,10000000);
NSInteger rows =
model.pictures.count%3==0?model.pictures.count/3:model.pictures.count/3+1;
for (int i =0; i<rows; i++) {
CGRectDivide(bounds, &aRect, &bounds,
90, CGRectMinYEdge);
for (int m =0; m<3;
m++) {
NSInteger index = i *
3 + m;
if (index >=
model.pictures.count) {
return;
}
CGRectDivide(aRect, &bRect, &aRect, bounds.size.width/3,CGRectMinXEdge);
UploadFileDto *fileDto = [model.picturesobjectAtIndex:index];
UIButton *button = [UIButtonbuttonWithType:UIButtonTypeCustom];
button.frame = bRect;
[buttonsd_setImageWithURL:[NSURLURLWithString:fileDto.url]forState:UIControlStateNormal];
[button
addTarget:selfaction:@selector(showImage:)forControlEvents:UIControlEventTouchUpInside];
[self.contentViewaddSubview:button];
}
}
}
//2.放大图片
-(void)showImage:(UIButton *)button{
UIWindow *window=[UIApplicationsharedApplication].keyWindow;
UIView *backgroundView=[[UIViewalloc]initWithFrame:CGRectMake(0,0,
[UIScreenmainScreen].bounds.size.width, [UIScreenmainScreen].bounds.size.height)];
oldframe=[button
convertRect:button.boundstoView:self.contentView];
backgroundView.backgroundColor=[UIColorblackColor];
backgroundView.alpha=0;
button.tag=1;
[backgroundViewaddSubview:button];
[windowaddSubview:backgroundView];
UITapGestureRecognizer *tap=[[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(hideImage:)];
[backgroundViewaddGestureRecognizer:tap];
[UIViewanimateWithDuration:0.3animations:^{
button.frame=CGRectMake(0,([UIScreenmainScreen].bounds.size.height-(button.frame.size.height*[UIScreenmainScreen].bounds.size.width/button.frame.size.width+80))/2,
[UIScreen mainScreen].bounds.size.width, button.frame.size.height*[UIScreenmainScreen].bounds.size.width/button.frame.size.width+80);
backgroundView.alpha=1;
}completion:^(BOOL finished) {
button.userInteractionEnabled=NO;
}];
}
//3.还原图片
-(void)hideImage:(UITapGestureRecognizer*)tap{
UIView *backgroundView=tap.view;
UIButton *button=(UIButton *)[tap.viewviewWithTag:1];
[UIViewanimateWithDuration:0.3animations:^{
button.frame=oldframe;
backgroundView.alpha=0;
}completion:^(BOOL finished) {
[backgroundViewremoveFromSuperview];
[self.contentViewaddSubview:button];
button.userInteractionEnabled=YES;
}];
}
@end
#import <UIButton+WebCache.h>
staticCGRect oldframe;//用于记录放大之前的frame
@implementation xxxCell
- (void)awakeFromNib {
}
//1.给cell赋值
-(void)reDrawInfoContentView:(xxxModel*)model{
CGRect aRect, bRect, bounds =
CGRectMake(10, height +
25, self.contentView.bounds.size.width,10000000);
NSInteger rows =
model.pictures.count%3==0?model.pictures.count/3:model.pictures.count/3+1;
for (int i =0; i<rows; i++) {
CGRectDivide(bounds, &aRect, &bounds,
90, CGRectMinYEdge);
for (int m =0; m<3;
m++) {
NSInteger index = i *
3 + m;
if (index >=
model.pictures.count) {
return;
}
CGRectDivide(aRect, &bRect, &aRect, bounds.size.width/3,CGRectMinXEdge);
UploadFileDto *fileDto = [model.picturesobjectAtIndex:index];
UIButton *button = [UIButtonbuttonWithType:UIButtonTypeCustom];
button.frame = bRect;
[buttonsd_setImageWithURL:[NSURLURLWithString:fileDto.url]forState:UIControlStateNormal];
[button
addTarget:selfaction:@selector(showImage:)forControlEvents:UIControlEventTouchUpInside];
[self.contentViewaddSubview:button];
}
}
}
//2.放大图片
-(void)showImage:(UIButton *)button{
UIWindow *window=[UIApplicationsharedApplication].keyWindow;
UIView *backgroundView=[[UIViewalloc]initWithFrame:CGRectMake(0,0,
[UIScreenmainScreen].bounds.size.width, [UIScreenmainScreen].bounds.size.height)];
oldframe=[button
convertRect:button.boundstoView:self.contentView];
backgroundView.backgroundColor=[UIColorblackColor];
backgroundView.alpha=0;
button.tag=1;
[backgroundViewaddSubview:button];
[windowaddSubview:backgroundView];
UITapGestureRecognizer *tap=[[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(hideImage:)];
[backgroundViewaddGestureRecognizer:tap];
[UIViewanimateWithDuration:0.3animations:^{
button.frame=CGRectMake(0,([UIScreenmainScreen].bounds.size.height-(button.frame.size.height*[UIScreenmainScreen].bounds.size.width/button.frame.size.width+80))/2,
[UIScreen mainScreen].bounds.size.width, button.frame.size.height*[UIScreenmainScreen].bounds.size.width/button.frame.size.width+80);
backgroundView.alpha=1;
}completion:^(BOOL finished) {
button.userInteractionEnabled=NO;
}];
}
//3.还原图片
-(void)hideImage:(UITapGestureRecognizer*)tap{
UIView *backgroundView=tap.view;
UIButton *button=(UIButton *)[tap.viewviewWithTag:1];
[UIViewanimateWithDuration:0.3animations:^{
button.frame=oldframe;
backgroundView.alpha=0;
}completion:^(BOOL finished) {
[backgroundViewremoveFromSuperview];
[self.contentViewaddSubview:button];
button.userInteractionEnabled=YES;
}];
}
@end
相关文章推荐
- GUI - Web前端开发框架
- Android布局的小窍门?
- Web布局连载——两栏固定布局(五)
- 评价ui设计作品好坏的八个标准(界面/交互设计研究)
- 按右键另存图片只能存BMP
- photoshop去除图片上的水印
- 样式表CSS布局经验
- upload上传单张图片
- 图片引发的溢出危机(图)
- C#实现把彩色图片灰度化代码分享
- C#将图片和字节流互相转换并显示到页面上
- C#监控文件夹并自动给图片文件打水印的方法
- css网页布局中注意的几个问题小结
- DL.DT.DD实现左右的布局简单例子第1/2页
- 使用CSS框架布局的缺点和优点小结
- div+CSS网页布局的意义与副作用原因小结第1/2页
- 纯CSS实现的当鼠标移上图片添加阴影效果代码
- C#实现打开画图的同时载入图片、最大化显示画图窗体的方法
- 随鼠标移动的图片或文字特效代码
- CSS 图片横向排列实现代码