iOS 点击图片放大Demo

发布时间:2016-12-6 8:57:04 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"iOS 点击图片放大Demo",主要涉及到iOS 点击图片放大Demo方面的内容,对于iOS 点击图片放大Demo感兴趣的同学可以参考一下。

创建UIImageView类目 添加一个方法 代码如下: .h #import <Foundation/Foundation.h> @interface UIImageView (UIImageViewEx) - (void)addDetailShow; @end .m #define kCoverViewTag           1234 #define kImageViewTag           1235 #define kAnimationDuration      0.3f #define kImageViewWidth         300.0f #define kBackViewColor          [UIColor colorWithWhite:0.667 alpha:1.f] #import "UIImageView+Addition.h" @implementation UIImageView (UIImageViewEx) - (void)hiddenView {     UIView *coverView = (UIView *)[[self window] viewWithTag:kCoverViewTag];     [coverView removeFromSuperview]; } - (void)hiddenViewAnimation {         UIImageView *imageView = (UIImageView *)[[self window] viewWithTag:kImageViewTag];          [UIView beginAnimations:nil context:nil];         [UIView setAnimationDuration:kAnimationDuration]; //动画时长     CGRect rect = [self convertRect:self.bounds toView:self.window];     imageView.frame = rect;          [UIView commitAnimations];     [self performSelector:@selector(hiddenView) withObject:nil afterDelay:kAnimationDuration];      } //自动按原UIImageView等比例调整目标rect - (CGRect)autoFitFrame {     //调整为固定宽,高等比例动态变化     float width = kImageViewWidth;     float targeHeight = (width*self.frame.size.height)/self.frame.size.width;     UIView *coverView = (UIView *)[[self window] viewWithTag:kCoverViewTag];     CGRect targeRect = CGRectMake(coverView.frame.size.width/2 - width/2, coverView.frame.size.height/2 - targeHeight/2, width, targeHeight);     return targeRect; } - (void)imageTap {         UIView *coverView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];     coverView.backgroundColor = kBackViewColor;     coverView.tag = kCoverViewTag;     UITapGestureRecognizer *hiddenViewGecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hiddenViewAnimation)];     [coverView addGestureRecognizer:hiddenViewGecognizer];     [hiddenViewGecognizer release];          UIImageView *imageView = [[UIImageView alloc] initWithImage:self.image];     imageView.tag = kImageViewTag;     imageView.userInteractionEnabled = YES;     imageView.contentMode = self.contentMode;     CGRect rect = [self convertRect:self.bounds toView:self.window];     imageView.frame = rect;             [coverView addSubview:imageView];     [[self window] addSubview:coverView];     [coverView release];          [UIView beginAnimations:nil context:nil];     [UIView setAnimationDuration:kAnimationDuration];         imageView.frame = [self autoFitFrame];      [UIView commitAnimations];       } - (void)addDetailShow {     self.userInteractionEnabled = YES;     UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTap)];     [self addGestureRecognizer:tapGestureRecognizer];     [tapGestureRecognizer release]; } @end =================================== 使用的时候 导入类目 直接添加这个addDetailShow方法就ok 如下:  UIImageView *imageView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_photo.png"]];     imageView2.frame = CGRectMake(100, 300, 100, 100);          //类目添加了这个方法 可以实现图片放大     [imageView2 addDetailShow];     [self.view addSubview:imageView2];     [imageView2 release];

上一篇:Javascript模块化编程(二):AMD规范
下一篇:使用ramdisk和cramfs

相关文章

相关评论