fullimgview

#import

//@protocol FullImgViewControllerDelegate

//- (void)tapClick;

//@end

@interface FullImgViewController : UIViewController

@property (nonatomic,strong) NSArray *urlArr;

@property (nonatomic,strong) NSArray *imageArr;

//第几张

@property (nonatomic,assign) NSInteger btnTag;

@property (weak, nonatomic) IBOutlet UIButton *lookDetailBtn;

@property (nonatomic,strong) NSString *pid;//作品id

@property (nonatomic,assign) NSInteger comeFrom;//2017.2.27 从帮我搭配过来给 1 原来的放else

//@property (nonatomic,strong) iddelegate;

@end




#import "UIImage+Image.h" //根据颜色生成图片

#import "ImageShowCell.h"

#define IMAGESHOWCELL @"ImageShowCell"

#define GRAYCOLOR2 [UIColor lightGrayColor]

@interface FullImgViewController ()

{

    __weakIBOutletUILabel*mNumLabel;

    __weakIBOutletUICollectionView*mCollection;

    NSMutableArray*mUrlArr;

    NSIntegerimageNum;

}

@end

@implementation FullImgViewController

- (void)viewWillAppear:(BOOL)animated {

    [superviewWillAppear:animated];

    [self.navigationController setNavigationBarHidden:YES animated:NO];

}

- (void)viewDidLoad {

    [super viewDidLoad];

    if(![self.pidisEqualToString:@""]) {

        self.lookDetailBtn.hidden=NO;

    }

    mUrlArr = [[NSMutableArray alloc]init];

    if(self.urlArr.count>0) {

        [mUrlArr addObjectsFromArray:self.urlArr];

    }

    else{

        [mUrlArr addObjectsFromArray:self.imageArr];

    }


    mNumLabel.text = [NSString stringWithFormat:@"%ld/%lu",(long)self.btnTag,(unsigned long)mUrlArr.count];

//    self.navigationController.navigationBar.hidden = YES;

    mCollection.backgroundColor = [UIColor blackColor];

    self.view.backgroundColor = [UIColor blackColor];

    [mCollection registerNib:[UINib nibWithNibName:IMAGESHOWCELL bundle:nil] forCellWithReuseIdentifier:IMAGESHOWCELL];


    mCollection.contentSize = CGSizeMake(SCREEN_WIDTH*mUrlArr.count, SCREEN_HEIGHT);

    mCollection.contentOffset = CGPointMake(SCREEN_WIDTH *(self.btnTag-1), 0);


}

- (UIStatusBarStyle)preferredStatusBarStyle

{

    if(@available(iOS13.0, *)) {

        return UIStatusBarStyleDarkContent;

    }else{

        return UIStatusBarStyleDefault;

    }


    //UIStatusBarStyleDefault = 0 黑色文字,浅色背景时使用

    //UIStatusBarStyleLightContent = 1 白色文字,深色背景时使用

}

- (BOOL)prefersStatusBarHidden

{

    return YES; // 返回NO表示要显示,返回YES将hiden

}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    returnmUrlArr.count;

}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    ImageShowCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:IMAGESHOWCELL forIndexPath:indexPath];

    cell.delegate=self;

    cell.contentView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);

    if ([mUrlArr[indexPath.row] isKindOfClass:[NSString class]]) {

        NSString*urlStr =mUrlArr[indexPath.row];

        NSURL*url;

        cell.progressLabel.hidden=YES;

        url = [NSURLURLWithString:urlStr];//2019.11.8

        [cell.imgView sd_setImageWithURL:url];

//        [cell.imgView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@""] options:SDWebImageAllowInvalidSSLCertificates progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {

//            dispatch_async(dispatch_get_main_queue(), ^{

//                int pro = (int)((float)receivedSize/(float)expectedSize*100);

//                if (pro>0) {

//

//                }

//                else{

//                    pro = 0;

//                }

//                cell.progressLabel.text = [NSString stringWithFormat:@"%d%@",pro,@"%"];

//            });

//        } completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {

//            dispatch_async(dispatch_get_main_queue(), ^{

//                cell.progressLabel.hidden = YES;

//            });

//

//        }];

    }

    else{

        cell.progressLabel.hidden=YES;

        cell.imgView.image=mUrlArr[indexPath.row];

    }


    returncell;

}

- (void)tapClick{

//    [self.delegate tapClick];

    [self.navigationController popViewControllerAnimated:NO];

}

//定义每个UICollectionView 的大小

- (CGSize)collectionView:(UICollectionView*)collectionViewlayout:(UICollectionViewLayout*)collectionViewLayoutsizeForItemAtIndexPath:(NSIndexPath*)indexPath

{

    return CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT);

}

-(UIEdgeInsets)collectionView:(UICollectionView*)collectionViewlayout:(UICollectionViewLayout*)collectionViewLayoutinsetForSectionAtIndex:(NSInteger)section

{

    return UIEdgeInsetsMake(0, 0, 0, 0);

}

- (void)scrollViewDidScroll:(UIScrollView*)scrollView{

    NSInteger num = (NSInteger)scrollView.contentOffset.x/SCREEN_WIDTH;

    NSLog(@"第%ld",(long)num);

    imageNum= num+1;

    mNumLabel.text = [NSString stringWithFormat:@"%ld/%lu",(long)imageNum,(unsigned long)mUrlArr.count];


}

- (IBAction)lookDetailClick:(id)sender {

}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

}

你可能感兴趣的:(fullimgview)