这两天更新pods仿佛经历了一个世纪,各种不兼容或者啥啥的
终于装好了,写个demo试试
可能文章有点乱,试着接受下
新建一个view类
@implementation ImgV
+(instancetype)sharedInstance
{
staticdispatch_once_t once;
staticid _instance;
dispatch_once(&once, ^{
_instance = [[selfalloc]init];
});
return _instance;
}
/*
imgName 图片名字 flag:是否是url
*/
-(void)showImgView:(NSString *)imgName flag:(BOOL)flag{
self.frame =CGRectMake(0,0,MAXWIDTH,MAXHEIGHT);
self.backgroundColor = [UIColorwhiteColor];
UIImageView *imgV = [[UIImageViewalloc]initWithFrame:CGRectMake(0,MAXHEIGHT/4,MAXWIDTH,MAXHEIGHT/2)];
if(flag ==YES){
[imgV sd_setImageWithURL:[NSURLURLWithString:imgName]placeholderImage:IMAGENAMED(@"testpodImg")];
}else{
imgV.image = [UIImageimageNamed:imgName];
}
imgV.userInteractionEnabled =YES;
[selfaddSubview:imgV];
UITapGestureRecognizer *tap = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(tap)];
tap.numberOfTouchesRequired =1;
[imgV addGestureRecognizer:tap];
}
-(void)tap{
[selfremoveFromSuperview];
}
在需要点击的图片事件上运用
-(void)newViewImg{
[[ImgVsharedInstance]showImgView:@"testpodImg"flag:NO];
[selfaddSubview:[ImgVsharedInstance]];
}
好啦,一个简单点击图片放大的效果就完成了。
文章附带demo
链接: https://pan.baidu.com/s/1hrUDUKG 密码: 9f9u