123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- #import "TileViewController.h"
- #import "SkimViewController.h"
- #import "UIImageView+WebCache.h"
- @interface TileViewController ()
- {
- NSArray *_imageNames;
- UIScrollView *_scrollView;
- }
- @end
- @implementation TileViewController
- - (instancetype)initWithImageNames:(NSArray *)imageNames
- {
- if (self = [super init]) {
- _imageNames = [[NSArray alloc] initWithArray:imageNames];
-
- }
- return self;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.navigationItem.title = @"培训照片";
- self.view.backgroundColor = backGroundColor;
- [self configNavigationBar];
-
- //创建滚动视图
- [self createScrollView];
- //创建图片视图
- [self createImageViews];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (void)createScrollView
- {
- //取消对滚动视图内容的布局的影响
- if (@available(iOS 11.0, *)) {
- _scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- }else {
- self.automaticallyAdjustsScrollViewInsets = NO;
- }
- CGSize size = self.view.frame.size;
- _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height-kNavOffSet-kSafeAreaBottomHeight)];
- [self.view addSubview:_scrollView];
- }
- - (void)createImageViews
- {
- CGSize size = _scrollView.frame.size;
- CGFloat gap = 10;
- CGFloat width = size.width/2-gap;
- CGFloat height = width*3/4;//width*3/2
- for (NSInteger i=0; i<_imageNames.count; i++) {
- UIImageView *imageView = [[UIImageView alloc] init];
- [imageView sd_setImageWithURL:[NSURL URLWithString:_imageNames[i][@"url"]] placeholderImage:[UIImage imageNamed:@"NOImg"]];
- imageView.frame = CGRectMake(gap/2+i%2*(width+gap), gap+i/2*(height+gap), width, height);
-
- [_scrollView addSubview:imageView];
- _scrollView.contentSize = CGSizeMake(0, gap+(_imageNames.count+1)/2*(gap+height));
-
- //添加手势
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapHandle:)];
- [imageView addGestureRecognizer:tap];
- //使用tag值记录图片数组中的下标
- imageView.tag = i;
- //打开交互
- imageView.userInteractionEnabled = YES;
- }
- }
- - (BOOL)prefersStatusBarHidden
- {
- return self.navigationController.navigationBarHidden;
- }
- - (void)tapHandle:(UITapGestureRecognizer *)tap
- {
- SkimViewController *svc = [[SkimViewController alloc] initWithImageNames:_imageNames index:tap.view.tag];
- if ([self.parentViewController isKindOfClass:[UINavigationController class]]) {
- [self navPushHideTabbarToVC:svc];
- }else{
- [self.parentViewController navPushHideTabbarToVC:svc];
- }
-
-
- //告诉应用程序状态栏需要刷新(9.0以后不用管)
- [self setNeedsStatusBarAppearanceUpdate];
-
- }
- @end
|