#import <UIKit/UIKit.h>
@interface ChangeScaleView : UIImageView
@property(nonatomic,strong)UIScrollView *scrollView;
@property(nonatomic,strong)UIImageView *scaleImageView;
@end
#import "ChangeScaleView.h"
@implementation ChangeScaleView
-(instancetype)initWithFrame:(CGRect)frame{
if ([super initWithFrame:frame]) {
[self createTap];
}
return self;
}
-(void)createTap{
self.userInteractionEnabled = YES;
// 初始化手势
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
[self addGestureRecognizer:tapGesture];
}
#pragma mark - 放大手势的响应事件
-(void)tapAction:(UITapGestureRecognizer *)tap{
[self createView];
[UIView animateWithDuration:.5 animations:^{
_scaleImageView.frame = _scrollView.frame;
_scrollView.backgroundColor = [UIColor orangeColor];
self.hidden = YES;
}];
}
-(void)createView{
//初始化滑动视图
_scrollView = [[UIScrollView alloc] initWithFrame:[UIScreen mainScreen].bounds];
_scrollView.showsHorizontalScrollIndicator = NO;
_scrollView.showsVerticalScrollIndicator = NO;
[self.window addSubview:_scrollView];
// 移到原来所在位置
CGRect frame = [self convertRect:self.bounds toView:self.window];
_scaleImageView = [[UIImageView alloc] initWithFrame:frame];
_scaleImageView.image = self.image;
_scaleImageView.userInteractionEnabled = YES;
//添加手势
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(smallTapGesture:)];
[_scaleImageView addGestureRecognizer:tap];
[_scrollView addSubview:_scaleImageView];
}
//缩小手势的响应事件
-(void)smallTapGesture:(UITapGestureRecognizer *)tap{
[UIView animateWithDuration:.3 animations:^{
_scaleImageView.frame = self.frame;
} completion:^(BOOL finished) {
self.hidden = NO;
[_scrollView removeFromSuperview];
}];
}