简单的点击图片放大功能

//.h文件

+(void)showImageArray:(NSArray*)imageArray index:(NSInteger)index;

//.m文件

+(void)showImageArray:(NSArray*)imageArray index:(NSInteger)index

{

UIWindow *window=[UIApplication sharedApplication].keyWindow;

UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];

scrollView.pagingEnabled = YES;

scrollView.showsVerticalScrollIndicator = NO;

scrollView.showsHorizontalScrollIndicator = NO;

scrollView.backgroundColor = [UIColor clearColor];

scrollView.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width * imageArray.count, 0);

[window addSubview:scrollView];

[imageArray enumerateObjectsUsingBlock:^(NSString  *_Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {

UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(idx*[UIScreen mainScreen].bounds.size.width, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];

image.tag=1;

image.image = [UIImage imageNamed:obj];

[scrollView addSubview:image];

}];

UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hideImage:)];

[scrollView addGestureRecognizer: tap];

}

+(void)hideImage:(UITapGestureRecognizer*)tap

{

UIView *backgroundView=tap.view;

UIImageView *imageView=(UIImageView*)[tap.view viewWithTag:1];

[UIView animateWithDuration:0.3 animations:^{

} completion:^(BOOL finished) {

[backgroundView removeFromSuperview];

}];

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • *7月8日上午 N:Block :跟一个函数块差不多,会对里面所有的内容的引用计数+1,想要解决就用__block...
    炙冰阅读 7,416评论 1 14
  • 两年前大师问我 什么是三一律 我摸摸脸 时间空间情节的统一 服务于一个主题 那时的我 优秀得想被骂 两年后 大师又...
    五色浮元子_阅读 1,454评论 0 1
  • 001.扩大能力圈,圈内游走,圈外慎重 我们从呱呱落地起,就开始接受父母教育, 然后幼儿园、小学、初中、高中、大学...
    玉儿说阅读 2,675评论 3 3
  • 近几年的生活中,从事某些事情或者在某种状态中让我感觉很快乐,幸福。这些事情或状态外部表现形式可以是多种多样的:可以...
    plg519gmailcom阅读 5,319评论 0 1

友情链接更多精彩内容