简单的点击图片放大功能

简单的点击图片放大功能_第1张图片

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

}];

}

你可能感兴趣的:(简单的点击图片放大功能)