首页 技术 正文
技术 2022年11月15日
0 收藏 940 点赞 3,451 浏览 2668 个字

当我们点击Cell中的某个图片时,图片会有一种从Cell中取出,放大,然后再回到原来的Cell中的效果。我的想法是:当Cell中的图片用button 来显示。当我们点击Cell中的这个button的时候,button触发方法以代理的方式将button的图片和这个Cell 传递到视图控制器。视图控制器通过坐标转换,得出图片在屏幕的位置坐标,然后保存这个位置并根据这个Frame在主视图创建一个ImageView。控制这个imageView的位置变化即可达到取出放大退回原有位置的效果。

//
// MyCell.h
// 自定义Cell
//
// Created by 邓竹立 on 15-3-18.
// Copyright (c) 2015年 邓竹立. All rights reserved.
//#import <UIKit/UIKit.h>@protocol MyCellDelagate <NSObject>-(void)image:(UIImage *)image rect:(CGRect) rect from:(UIView*)view;@end
@interface MyCell : UITableViewCell
@property (weak, nonatomic) UIButton *iconButton;
@property(nonatomic,weak)id<MyCellDelagate> myDelgate;+(instancetype)cellWithTableView:(UITableView *)tableView;@end
//
// MyCell.m
// 自定义Cell
//
// Created by 邓竹立 on 15-3-18.
// Copyright (c) 2015年 邓竹立. All rights reserved.
//#import "MyCell.h"@interface MyCell ()@end@implementation MyCell- (void)clickIconButton:(UIButton *)sender
{
[self.myDelgate image:sender.imageView.image rect:sender.frame from:self.contentView];
}+(instancetype)cellWithTableView:(UITableView *)tableView
{
static NSString *reuseId=@"cell";
MyCell *cell=[tableView dequeueReusableCellWithIdentifier:reuseId];
if (!cell)
{
cell=[[MyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseId];
} UIButton *button=[[UIButton alloc]init]; cell.iconButton=button;
button.frame=CGRectMake(0, 0, 120, 120); [cell.iconButton setImage:[UIImage imageNamed:@"DSC00003.jpg"] forState:UIControlStateNormal];
[cell.iconButton addTarget:cell action:@selector(clickIconButton:) forControlEvents:
UIControlEventTouchUpInside];
[cell.contentView addSubview:button];
return cell;
}@end
#import "ViewController.h"
#import "MyCell.h"
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate,MyCellDelagate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;@end@implementation ViewController- (void)viewDidLoad
{
[super viewDidLoad]; self.tableView.delegate=self;
self.tableView.dataSource=self;
self.tableView.allowsSelection=NO;
}
-(void)image:(UIImage *)image rect:(CGRect)rect from:(UIView *)view
{
UIImageView *imageView=[[UIImageView alloc] init];
CGRect rect1=[view convertRect:rect toView:self.view]; imageView.frame=CGRectMake(rect1.origin.x+100, rect1.origin.y+100, rect1.size.width, rect1.size.height);
imageView.image=image;
[self.view addSubview:imageView];
}-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 5;
}-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MyCell *cell=[MyCell cellWithTableView:tableView];
cell.myDelgate=self; return cell;
}-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 200;
}- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}@end
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,983
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,500
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,344
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,127
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,762
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,838