iOS开发 UI高级 图片放大缩小的实现
#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];
        
    }];
}


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/A_Studystudy/article/details/52347640
文章标签: ios开发 图片 ui
个人分类: 图片
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

iOS开发 UI高级 图片放大缩小的实现

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭