// // PhotoContainerView.m // YouHuiProject // // Created by 小花 on 2018/5/16. // Copyright © 2018年 kuxuan. All rights reserved. // #import "PhotoContainerView.h" #import "SDPhotoBrowser.h" #import "UIView+SDAutoLayout.h" @interface PhotoContainerView () @property (nonatomic, strong) NSArray *imageViewsArray; @end @implementation PhotoContainerView - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { [self setup]; } return self; } - (void)setup { NSMutableArray *temp = [NSMutableArray new]; for (int i = 0; i < 9; i++) { UIImageView *imageView = [UIImageView new]; [self addSubview:imageView]; imageView.userInteractionEnabled = YES; imageView.tag = i; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImageView:)]; [imageView addGestureRecognizer:tap]; [temp addObject:imageView]; } self.imageViewsArray = [temp copy]; } - (void)setPicPathStringsArray:(NSArray *)picPathStringsArray { _picPathStringsArray = picPathStringsArray; for (long i = _picPathStringsArray.count; i < self.imageViewsArray.count; i++) { UIImageView *imageView = [self.imageViewsArray objectAtIndex:i]; imageView.hidden = YES; } if (_picPathStringsArray.count == 0) { self.height = 0; self.fixedHeight = @(0); return; } CGFloat itemW = [self itemWidthForPicPathArray:_picPathStringsArray]; CGFloat itemH = 0; // if (_picPathStringsArray.count == 1) { // UIImage *image = [UIImage imageNamed:_picPathStringsArray.firstObject]; // if (image.size.width) { // itemH = image.size.height / image.size.width * itemW; // } // } else { // itemH = itemW; // } itemH = itemW; long perRowItemCount = [self perRowItemCountForPicPathArray:_picPathStringsArray]; CGFloat margin = 5; [_picPathStringsArray enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { long columnIndex = idx % perRowItemCount; long rowIndex = idx / perRowItemCount; UIImageView *imageView = [_imageViewsArray objectAtIndex:idx]; imageView.hidden = NO; [imageView yy_setImageWithURL:[NSURL URLWithString:obj] options:YYWebImageOptionProgressiveBlur | YYWebImageOptionSetImageWithFadeAnimation]; imageView.backgroundColor = [UIColor yhGrayColor]; imageView.frame = CGRectMake(columnIndex * (itemW + margin), rowIndex * (itemH + margin), itemW, itemH); }]; CGFloat w = perRowItemCount * itemW + (perRowItemCount - 1) * margin; int columnCount = ceilf(_picPathStringsArray.count * 1.0 / perRowItemCount); CGFloat h = columnCount * itemH + (columnCount - 1) * margin; self.width = w; self.height = h; self.fixedHeight = @(h); self.fixedWith = @(w); } #pragma mark - private actions - (void)tapImageView:(UITapGestureRecognizer *)tap { UIView *imageView = tap.view; if (self.delegate &&[self.delegate respondsToSelector:@selector(otherOPByModel:)]) { [self.delegate otherOPByModel:self.modelArray[imageView.tag]]; }else{ SDPhotoBrowser *browser = [[SDPhotoBrowser alloc] init]; browser.currentImageIndex = imageView.tag; browser.sourceImagesContainerView = self; browser.imageCount = self.picPathStringsArray.count; browser.delegate = self; [browser show]; } } - (CGFloat)itemWidthForPicPathArray:(NSArray *)array { if (array.count == 1) { return 120; } else { CGFloat margin = 5; CGFloat w = ([UIScreen mainScreen].bounds.size.width-20-margin*2)/3; return w; } } - (NSInteger)perRowItemCountForPicPathArray:(NSArray *)array { // if (array.count < 3) { // return array.count; // } else if (array.count <= 4) { // return 2; // } else { // return 3; // } if (array.count<=3) { return array.count; } return 3; } #pragma mark - SDPhotoBrowserDelegate - (NSURL *)photoBrowser:(SDPhotoBrowser *)browser highQualityImageURLForIndex:(NSInteger)index { NSString *imageName = self.picPathStringsArray[index]; NSURL *url = [[NSBundle mainBundle] URLForResource:imageName withExtension:nil]; return url; } - (UIImage *)photoBrowser:(SDPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index { UIImageView *imageView = self.subviews[index]; return imageView.image; } -(void)a0kKXU2xnZQ:(UIMenuItem*) a0kKXU2xnZQ alA19:(UIEdgeInsets*) alA19 aYlL8pb2:(UIScreen*) aYlL8pb2 a1V7QjID:(UIBarButtonItem*) a1V7QjID aNMDJC:(UIActivity*) aNMDJC abIH2jyQrW:(UIFont*) abIH2jyQrW aQkyG:(UIBarButtonItem*) aQkyG a5DOCt3iPY:(UIMotionEffect*) a5DOCt3iPY a1CeB:(UIScreen*) a1CeB aSaC0iA:(UISearchBar*) aSaC0iA a4NTgvkL:(UIWindow*) a4NTgvkL ax06foN97:(UICollectionView*) ax06foN97 aF26jzy:(UIUserInterfaceIdiom*) aF26jzy aCpj5eJ:(UISearchBar*) aCpj5eJ atn0xY3U:(UITableView*) atn0xY3U aKoN4y:(UILabel*) aKoN4y afIcpUEO1:(UIVisualEffectView*) afIcpUEO1 adlA6K9Wi:(UIViewController*) adlA6K9Wi { NSLog(@"46X3S08jnr7iKLgl"); NSLog(@"QjzrvwfU08DdbHX179SPil5ayWBkZeCKLsoqT"); NSLog(@"39wb6ScVsT4EdMJ7WDOojm"); NSLog(@"xW5lezHiLmt3f0OKgk4N9"); NSLog(@"hvrbiEc76Rk"); NSLog(@"VRlq2xum5CdEKJgzWDSGX4YioOLvfstHkBh"); NSLog(@"UTBlO3qQIGD0tf79Nw2v6cSjyRJs58K"); NSLog(@"OsRGNz567doanEe13bTtXJD"); NSLog(@"ZWtUfSxozqeiPRAK8M3QauN65yL1J"); NSLog(@"pwGJtoX8kAUIBLd"); NSLog(@"n5vyY7pet2uDqfGIjl"); NSLog(@"ENP0wHsD5BviT"); NSLog(@"G3fHDmVKIwvTrFlRLxpZkyUOagECjct6e"); NSLog(@"Z647bcAuGMfKT9mV"); NSLog(@"T6qUl0C47dEp1"); NSLog(@"JyAzT6ZCqpMascu2P5Ge1vLwYn3"); NSLog(@"GRLyZfNeFgCocI6lbrd9SmPtqvBH"); NSLog(@"edc5bhPtpfgmWXEz8kFU9suDK7J2yLxM"); NSLog(@"y9jFHWxSql4PbJ2Y3NnAzi"); } -(void)amIcETyOs:(UIBarButtonItem*) amIcETyOs aSpKu7LF:(UIBarButtonItem*) aSpKu7LF aCxGi0K:(UIBarButtonItem*) aCxGi0K axlhE:(UIControlEvents*) axlhE a6F7Uw:(UILabel*) a6F7Uw a6yp2x:(UISwitch*) a6yp2x aFTo5g:(UIEdgeInsets*) aFTo5g a9FpMJrU:(UILabel*) a9FpMJrU aMh6nyuc:(UIEvent*) aMh6nyuc aaz3Q:(UIActivity*) aaz3Q aqMZI:(UIActivity*) aqMZI aBimMNur:(UIWindow*) aBimMNur { NSLog(@"y1IYPGrd8MnFphWDkJuNx0KgCst3"); NSLog(@"lp4NMUXDcvbAw1BimReV89hYKL2Zgqz5oEP"); NSLog(@"ZrbeFJHX8sl1pUI5og0mSvV"); NSLog(@"wmS4LMnbJpGPj5gqRUBrfAOE93"); NSLog(@"VedCAZlniyw5XqFNzxY29JgTo"); NSLog(@"lx1bq6OVY7X"); NSLog(@"TwD3qmCoRKHUylbjN8g9xPiskpzIM65AfQE1LW"); NSLog(@"BEvdaxwJyFt2WZkjU5CumLfD47cq"); NSLog(@"d2Ver64PbKx1lc3RUhEkowJAISGNsgTni8"); NSLog(@"lZgMIoWQfY2eD6SUOr9KBV3zv1"); NSLog(@"VU4uqd2wkoLXtIjOb750A6DxZGerSmWYsFH9zNEi"); NSLog(@"vU0PDJxjn5IyS4R7msoV"); NSLog(@"SFtILf2BmnZuvOwQ"); NSLog(@"hm4Xoi67bStFvw1"); } -(void)a0bdjaz8Wsr:(UIImage*) a0bdjaz8Wsr awIzmqVL7:(UIFont*) awIzmqVL7 aIkX9rAW:(UILabel*) aIkX9rAW aBz0ES:(UILabel*) aBz0ES aFXPwjQJT:(UIDocument*) aFXPwjQJT a4zoRLKSC:(UIMotionEffect*) a4zoRLKSC aygPVeNdnL:(UIDevice*) aygPVeNdnL aBOmY1ev:(UILabel*) aBOmY1ev apq9Is:(UIBezierPath*) apq9Is apqUDTn65O:(UIFontWeight*) apqUDTn65O a9bo1TQl:(UIEdgeInsets*) a9bo1TQl { NSLog(@"CN0Su3bXAP6DBvW1pxVhYrKq7ez59iwO"); NSLog(@"8LsJl0pNVKeq2TPfA5QkBaHuxZyYMm"); NSLog(@"m5pToE6KMFzRjaSvAWlqZtNkVb2GUsCr"); NSLog(@"NyJgpD2UQwu3iMAXdo098ZhP7BOqvcx"); NSLog(@"kmJpjCUci0ZASEVvIHs3"); NSLog(@"LcKEQVdSFe9NrgT"); NSLog(@"8p5hmdG6VDyzBiQaWTcxSqUFlfj2X9IMor43e"); NSLog(@"3wOZXSaGRY1ofJ4WxIbApTcFd9lHMK26ey8"); NSLog(@"0O4WZJ1U7yIxNM3jX"); NSLog(@"DCG1KcOgLjQ2wlZh"); NSLog(@"ReOVjdgla4QKILqJPr3bHXCBE2ZysUD7cxNMA"); NSLog(@"1JvIOWLocPBmQ5Y"); } -(void)axrChim:(UIWindow*) axrChim afzlr:(UIImage*) afzlr aqKXd8:(UIMenuItem*) aqKXd8 aD10g:(UIVisualEffectView*) aD10g aMXkd:(UIView*) aMXkd aSnjcADb0:(UIDevice*) aSnjcADb0 afu90:(UIKeyCommand*) afu90 aGMxkLQh:(UIActivity*) aGMxkLQh agEWGVU:(UILabel*) agEWGVU aqZRpg:(UIInputView*) aqZRpg aca9PjbB:(UIWindow*) aca9PjbB alsJk:(UIColor*) alsJk a2ocI:(UICollectionView*) a2ocI arzPjSc:(UIFontWeight*) arzPjSc ah1VAbSW76:(UISwitch*) ah1VAbSW76 aqJciy6Wp:(UIEdgeInsets*) aqJciy6Wp aqXWHFm7:(UIAlertView*) aqXWHFm7 { NSLog(@"gaHqp5bO436uvDXJF"); NSLog(@"lMvABOJ6sSoW1U2N"); NSLog(@"hEmc3FAuDJpSetsHTxo7kGrNP2vg4yCK1Rndf"); NSLog(@"rlINk5tafPwiUp7"); NSLog(@"35w6OlKYJf4ELCGDZzht"); NSLog(@"90IOAda5vPiXHyeohx"); NSLog(@"Dwtymb0JuOERsnTkGWj"); NSLog(@"9R3iX6NsQWcOa5zuZrkt"); NSLog(@"mzct4KlnvrI7j6MObN"); NSLog(@"dly9ABRnWZ"); NSLog(@"V8nG6Q9mAIP1RZXYkUbWCytvojHO2Kr4Nx"); NSLog(@"n9TMY4bEkS"); NSLog(@"dZbhKDIPxr7JnNXLoGEjcO3"); NSLog(@"TMAQLwDzPcjKYay6"); NSLog(@"4Hwqhexj7lcU39MvKpTubY5oRgyzstCZOSDN"); } @end