簡單的點擊圖片放大功能

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

}];

}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • *7月8日上午 N:Block :跟一個函數塊差不多,會對里面所有的內容的引用計數+1,想要解決就用__block...
    炙冰閱讀 2,547評論 1 14
  • 兩年前大師問我 什么是三一律 我摸摸臉 時間空間情節的統一 服務于一個主題 那時的我 優秀得想被罵 兩年后 大師又...
    五色浮元子_閱讀 190評論 0 1
  • 001.擴大能力圈,圈內游走,圈外慎重 我們從呱呱落地起,就開始接受父母教育, 然后幼兒園、小學、初中、高中、大學...
    玉兒說閱讀 332評論 3 3
  • 近幾年的生活中,從事某些事情或者在某種狀態中讓我感覺很快樂,幸福。這些事情或狀態外部表現形式可以是多種多樣的:可以...
    plg519gmailcom閱讀 1,482評論 0 1