iOS开发——UIImageView
2016-03-23 10:59
417 查看
1.图像点击之后,全屏浏览
- (void)viewDidLoad {
[super viewDidLoad];
_myImage=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, klScreenWidth, klScreenHeight-270)];
_myImage.userInteractionEnabled=YES;
[self.scrollview addSubview:_myImage];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showZoomImageView:)];
tapGesture.numberOfTapsRequired=1;
[_myImage addGestureRecognizer:tapGesture];
}
-(void)showZoomImageView:(UITapGestureRecognizer *)tap
{
if (![(UIImageView *)tap.view image]) {
return;
}
//scrollView作为背景
UIScrollView *bgView = [[UIScrollView alloc] init];
bgView.frame = [UIScreen mainScreen].bounds;
bgView.backgroundColor = [UIColor blackColor];
UITapGestureRecognizer *tapBg = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapBgView:)];
[bgView addGestureRecognizer:tapBg];
UIImageView *picView = (UIImageView *)tap.view;
UIImageView *imageView = [[UIImageView alloc] init];
imageView.image = picView.image;
imageView.frame = [bgView convertRect:picView.frame fromView:self.view];
[bgView addSubview:imageView];
[[[UIApplication sharedApplication] keyWindow] addSubview:bgView];
[UIView animateWithDuration:0.5 animations:^{
CGRect frame = imageView.frame;
frame.size.width = bgView.frame.size.width;
frame.size.height = frame.size.width * (imageView.image.size.height / imageView.image.size.width);
frame.origin.x = 0;
frame.origin.y = (bgView.frame.size.height - frame.size.height) * 0.5;
imageView.frame = frame;
}];
}
2.图片的缩放
@interface ViewController () <UIScrollViewDelegate>{
UIScrollView *_scrollview;
UIImageView *_imageview;
}
- (void)viewDidLoad {
[super viewDidLoad];
_scrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
_scrollview.delegate=self;
//设置最大伸缩比例
_scrollview.maximumZoomScale=5.0;
//设置最小伸缩比例
_scrollview.minimumZoomScale=1;
[self.view addSubview:_scrollview];
UIImage *image=[UIImage imageNamed:@"1"];
_imageview=[[UIImageView alloc]initWithImage:image];
_imageview.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
_imageview.userInteractionEnabled = YES;
[_scrollview addSubview:_imageview];
}
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return _imageview;
}
- (void)viewDidLoad {
[super viewDidLoad];
_myImage=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, klScreenWidth, klScreenHeight-270)];
_myImage.userInteractionEnabled=YES;
[self.scrollview addSubview:_myImage];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showZoomImageView:)];
tapGesture.numberOfTapsRequired=1;
[_myImage addGestureRecognizer:tapGesture];
}
-(void)showZoomImageView:(UITapGestureRecognizer *)tap
{
if (![(UIImageView *)tap.view image]) {
return;
}
//scrollView作为背景
UIScrollView *bgView = [[UIScrollView alloc] init];
bgView.frame = [UIScreen mainScreen].bounds;
bgView.backgroundColor = [UIColor blackColor];
UITapGestureRecognizer *tapBg = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapBgView:)];
[bgView addGestureRecognizer:tapBg];
UIImageView *picView = (UIImageView *)tap.view;
UIImageView *imageView = [[UIImageView alloc] init];
imageView.image = picView.image;
imageView.frame = [bgView convertRect:picView.frame fromView:self.view];
[bgView addSubview:imageView];
[[[UIApplication sharedApplication] keyWindow] addSubview:bgView];
[UIView animateWithDuration:0.5 animations:^{
CGRect frame = imageView.frame;
frame.size.width = bgView.frame.size.width;
frame.size.height = frame.size.width * (imageView.image.size.height / imageView.image.size.width);
frame.origin.x = 0;
frame.origin.y = (bgView.frame.size.height - frame.size.height) * 0.5;
imageView.frame = frame;
}];
}
2.图片的缩放
@interface ViewController () <UIScrollViewDelegate>{
UIScrollView *_scrollview;
UIImageView *_imageview;
}
- (void)viewDidLoad {
[super viewDidLoad];
_scrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
_scrollview.delegate=self;
//设置最大伸缩比例
_scrollview.maximumZoomScale=5.0;
//设置最小伸缩比例
_scrollview.minimumZoomScale=1;
[self.view addSubview:_scrollview];
UIImage *image=[UIImage imageNamed:@"1"];
_imageview=[[UIImageView alloc]initWithImage:image];
_imageview.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
_imageview.userInteractionEnabled = YES;
[_scrollview addSubview:_imageview];
}
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return _imageview;
}
相关文章推荐
- UITableView分割线从边框顶端开始
- Android Activity.runOnUiThread() 和 Handler
- 【学渣笔记】Xitrum Scala Web Framework Guide
- iOS UITableCell复用
- UIImageView的ContentMode属性
- Process 'command '**/ndk-build.cmd'' finished with non-zero exit value 1
- UIView的layoutSubviews和drawRect
- (转)Storm UI 解释
- marquee标签弹幕效果
- iOS-添加UINavigation
- dispatchTouchEvent
- QtQuick项目部署
- Java中Integer的valueOf方法,-128到127的整数将被缓存
- 使用fuel部署openstack时遇到的问题记录一下
- Java序列化之transient和serialVersionUID的使用
- UI元素状态伪类选择器
- 转 String,StringBuffer与StringBuilder的区别??
- Query 提交按钮置灰与恢复
- 小米手机 更新系统之后(MIUI 7.2稳定版) 拍照上传返回 取不到数据问题!
- PDE14 heat equation intuition