Open shuaiyinoo opened 8 years ago
(void)setPicPathStringsArray:(NSArray )picPathStringsArray { _picPathStringsArray = picPathStringsArray; [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; 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; } long perRowItemCount = [self perRowItemCountForPicPathArray:_picPathStringsArray]; CGFloat margin = 10; [_picPathStringsArray enumerateObjectsUsingBlock:^(NSString _Nonnull obj, NSUInteger idx, BOOL _Nonnull stop) { long columnIndex = idx % perRowItemCount; long rowIndex = idx / perRowItemCount; UIImageView imageView = [UIImageView new];
//加载网络图片 [imageView sd_setImageWithURL:[NSURL URLWithString:obj] placeholderImage:[UIImage imageNamed:@"placeholder.png"]]; //判断是多张图片还是一张图片 if (_picPathStringsArray.count > 1) { imageView.frame = CGRectMake(columnIndex * (itemW + margin), rowIndex * (itemH + margin), itemW, itemH); }else{ imageView.frame = CGRectMake(columnIndex * (itemW + margin), rowIndex * (itemH + margin), 100, 100); } [self addSubview:imageView]; imageView.userInteractionEnabled = YES; imageView.tag = idx; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImageView:)]; [imageView addGestureRecognizer:tap];
}]; CGFloat w = perRowItemCount itemW + (perRowItemCount - 1) margin; int columnCount = ceilf(_picPathStringsArray.count 1.0 / perRowItemCount); CGFloat h = columnCount itemH + (columnCount - 1) * margin; //NSLog(@"高度为%f 宽度为%f",h,w); if (_picPathStringsArray.count == 1) { h = 100; } self.width = w; self.height = h; self.fixedHeight = @(h); self.fixedWith = @(w); }
老哥,,你加载网络图片整个页面滑动卡顿么?
(void)setPicPathStringsArray:(NSArray *)picPathStringsArray { _picPathStringsArray = picPathStringsArray;
[self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
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; } long perRowItemCount = [self perRowItemCountForPicPathArray:_picPathStringsArray]; CGFloat margin = 10;
[_picPathStringsArray enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { long columnIndex = idx % perRowItemCount; long rowIndex = idx / perRowItemCount; UIImageView *imageView = [UIImageView new];
}];
CGFloat w = perRowItemCount * itemW + (perRowItemCount - 1) * margin; int columnCount = ceilf(_picPathStringsArray.count * 1.0 / perRowItemCount); CGFloat h = columnCount * itemH + (columnCount - 1) * margin;
//NSLog(@"高度为%f 宽度为%f",h,w); if (_picPathStringsArray.count == 1) { h = 100; }
self.width = w; self.height = h;
self.fixedHeight = @(h); self.fixedWith = @(w); }