iOS点击图片放大 再点击缩小
2016-08-19 17:51
218 查看
#import <Foundation/Foundation.h>
@interface MPAvatarBrowser : NSObject
+(void)showImage:(UIImageView*)avatarImageView;
@end
#import "MPAvatarBrowser.h"
static CGRect oldframe;
@implementation MPAvatarBrowser
+(void)showImage:(UIImageView *)avatarImageView{
UIImage *image=avatarImageView.image;
UIWindow *window=[UIApplication sharedApplication].keyWindow;
UIView *backgroundView=[[UIView alloc]initWithFrame:CGRectMake(0, 0,
[UIScreen mainScreen].bounds.size.width,
[UIScreenmainScreen].bounds.size.height)];
oldframe=[avatarImageView convertRect:avatarImageView.bounds toView:window];
backgroundView.backgroundColor=[UIColor blackColor];
backgroundView.alpha=0;
UIImageView *imageView=[[UIImageView alloc]initWithFrame:oldframe];
imageView.image=image;
imageView.tag=1;
[backgroundView addSubview:imageView];
[window addSubview:backgroundView];
UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hideImage:)];
[backgroundView addGestureRecognizer: tap];
[UIView animateWithDuration:0.3 animations:^{
imageView.frame=CGRectMake(0,([UIScreen mainScreen].bounds.size.height-image.size.height*[UIScreenmainScreen].bounds.size.width/image.size.width)/2,
[UIScreen mainScreen].bounds.size.width,
image.size.height*[UIScreenmainScreen].bounds.size.width/image.size.width);
backgroundView.alpha=1;
} completion:^(BOOL finished) {
}];
}
+(void)hideImage:(UITapGestureRecognizer*)tap{
UIView *backgroundView=tap.view;
UIImageView *imageView=(UIImageView*)[tap.view viewWithTag:1];
[UIView animateWithDuration:0.3 animations:^{
imageView.frame=oldframe;
backgroundView.alpha=0;
} completion:^(BOOL finished) {
[backgroundView removeFromSuperview];
}];
}
@end
然后调入头文件
调用
[MPAvatarBrowser showImage:weakCell.shopCartImage];
@interface MPAvatarBrowser : NSObject
+(void)showImage:(UIImageView*)avatarImageView;
@end
#import "MPAvatarBrowser.h"
static CGRect oldframe;
@implementation MPAvatarBrowser
+(void)showImage:(UIImageView *)avatarImageView{
UIImage *image=avatarImageView.image;
UIWindow *window=[UIApplication sharedApplication].keyWindow;
UIView *backgroundView=[[UIView alloc]initWithFrame:CGRectMake(0, 0,
[UIScreen mainScreen].bounds.size.width,
[UIScreenmainScreen].bounds.size.height)];
oldframe=[avatarImageView convertRect:avatarImageView.bounds toView:window];
backgroundView.backgroundColor=[UIColor blackColor];
backgroundView.alpha=0;
UIImageView *imageView=[[UIImageView alloc]initWithFrame:oldframe];
imageView.image=image;
imageView.tag=1;
[backgroundView addSubview:imageView];
[window addSubview:backgroundView];
UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hideImage:)];
[backgroundView addGestureRecognizer: tap];
[UIView animateWithDuration:0.3 animations:^{
imageView.frame=CGRectMake(0,([UIScreen mainScreen].bounds.size.height-image.size.height*[UIScreenmainScreen].bounds.size.width/image.size.width)/2,
[UIScreen mainScreen].bounds.size.width,
image.size.height*[UIScreenmainScreen].bounds.size.width/image.size.width);
backgroundView.alpha=1;
} completion:^(BOOL finished) {
}];
}
+(void)hideImage:(UITapGestureRecognizer*)tap{
UIView *backgroundView=tap.view;
UIImageView *imageView=(UIImageView*)[tap.view viewWithTag:1];
[UIView animateWithDuration:0.3 animations:^{
imageView.frame=oldframe;
backgroundView.alpha=0;
} completion:^(BOOL finished) {
[backgroundView removeFromSuperview];
}];
}
@end
然后调入头文件
调用
[MPAvatarBrowser showImage:weakCell.shopCartImage];
相关文章推荐
- iOS开发中,点击放大、缩小图片方法举例
- iOS 图片捏合放大缩小 点击放大缩小
- iOS点击button放大后缩小效果,类似QQ、微信选择图片时的特效。
- iOS 坐标转换,tableViewCell图片点击放大缩小回原位 —— HERO博客
- iOS 点击图片放大Demo
- 关于iPad+iPhone上,图片放大缩小时都能点击此区域
- 图片放大缩小的区域点击事件代码例子
- 图片放大缩小的区域点击事件代码例子
- ios 双指捏合放大缩小图片的例子
- 图片自动缩小 点击放大
- 基于jquery实现一张图片点击鼠标放大再点缩小
- 基于jquery实现一张图片点击鼠标放大再点缩小
- windows phone 8 双击图片,图片放大,再点击图片缩小。
- ios 根据手势放大或缩小图片
- 图片点击放大,再次点击返回原视图.完美封装,一个类一句代码即可调用.IOS完美实现
- 一张图片 点击鼠标放大,再点缩小 ( 基于jquery1.8.3), 另外推荐一款插件:lightBox...效果不错。
- ios 根据手势放大或缩小图片
- ios 图片拖拽,捏,双击放大缩小,以及保存到相册
- android点击实现图片放大缩小 - java技术博客
- highslide使用实例,点击图片放大效果,再次点击缩小