美文网首页
简单的点击图片放大功能

简单的点击图片放大功能

作者: 直男小金鱼 | 来源:发表于2016-10-15 17:01 被阅读0次

    //.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];

    }];

    }

    相关文章

      网友评论

          本文标题:简单的点击图片放大功能

          本文链接:https://www.haomeiwen.com/subject/vhfoyttx.html