在viewcontroller.h
@interface MainViewController : UIViewController
@property (strong, nonatomic) IBOutlet ZoomImgView *avatorimg;
在viewcontroller.m中
_avatorimg=[[ZoomImgView alloc]initWithFrame:CGRectMake(12, 11, 50, 50)];
_avatorimg.userInteractionEnabled=YES;
_avatorimg.layer.cornerRadius=25;
_avatorimg.layer.masksToBounds=YES;
[self.avatorimg sd_setImageWithURL:[NSURL URLWithString:imagestr] placeholderImage:kPlaceImgSmall];//首页头像
self.avatorimg.layer.masksToBounds = YES;
self.avatorimg.layer.cornerRadius = 4;
[_BeijingView addSubview:self.avatorimg];
封装的图片放大的类
在ZoomImgView.h
@interface ZoomImgView : UIImageView
@property(nonatomic,strong)UIScrollView *scrollView;
@property(nonatomic,strong)UIImageView *imgView;
@end
在zoomimageview.m中
#import "ZoomImgView.h"
@implementation ZoomImgView
-(instancetype)initWithFrame:(CGRect)frame{
if ([super initWithFrame:frame]) {
[self _inteTap];
}
return self;
}
- (void)_inteTap{
self.userInteractionEnabled = YES;
//添加手势
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapBig)];
[self addGestureRecognizer:tap];
}
- (void)tapBig{
//弹出来的视图
[self creactSubView];
//放大的动画
[UIView animateWithDuration:.3 animations:^{
_imgView.frame = CGRectMake(0, (kScreenH-300)/2, kScreenW, 300);
_scrollView.backgroundColor = [UIColor blackColor];
self.hidden = YES;
}];
}
- (void)creactSubView{
_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];
_imgView = [[UIImageView alloc] initWithFrame:frame];
_imgView.image = self.image;
_imgView.userInteractionEnabled = YES;
//添加手势
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(smallTap)];
[_imgView addGestureRecognizer:tap];
[_scrollView addSubview:_imgView];
}
- (void)smallTap{
[UIView animateWithDuration:.3 animations:^{
_imgView.frame = self.frame;
} completion:^(BOOL finished) {
self.hidden = NO;
[_scrollView removeFromSuperview];
}];
}
网友评论