从CSDN下载Demo源码:https://download.csdn.net/download/u011018979/16039540
在这里插入图片描述
避免多个数组下标不一致问题
- (void)showImageBrowser:(QCTCollectionModel*)m
{
[self setupImageBrowserModels];
KNImageBrowserViewController * imageBrowserViewController = [[KNImageBrowserViewController alloc] initWithImageBrowserModels:self.viewModel.ImageBrowserModels selectPage:m.selectPage];
// KNImageBrowserViewController * imageBrowserViewController = [[KNImageBrowserViewController alloc] initWithUrlStr:imageUrls originImageViews:imageView4smalls selectPage:m.selectPage];
[self presentViewController:imageBrowserViewController animated:YES completion:nil];
}
- (void)showImageBrowser {
KNImageBrowserViewController * imageBrowserViewController = [[KNImageBrowserViewController alloc] initWithUrlStr:self.imageUrls originImageViews:self.originImageViews selectPage:self.selectPage];
[self.controller presentViewController:imageBrowserViewController animated:YES completion:nil];
}
@interface KNImageBrowserModel : NSObject
/**
大图的图片地址
*/
@property(nonatomic,copy)NSString * urlStr;
/**
小图原始的imageView,用于加载大图时的展位图片
*/
@property(nonatomic,weak)UIImageView * smallImageView;
KNImageBrowserModel * imageBrowserModel = [[KNImageBrowserModel alloc] init];
imageBrowserModel.smallImageView = imageView;
imageBrowserModel.urlStr = urlStr;
- (void)setupImageBrowserModels{
// NSArray *imageView4smalls = [self.viewModel.collectionDataArray valueForKeyPath:@"@distinctUnionOfObjects.imageView4small"];//arDistinct是一些含有originalAddress属性的对象集合
//
// NSArray *imageUrls = [self.viewModel.collectionDataArray valueForKeyPath:@"@distinctUnionOfObjects.originalAddress"];//arDistinct是一些含有originalAddress属性的对象集合
self.viewModel.ImageBrowserModels = [NSMutableArray array];
for ( QCTCollectionModel *obj in self.viewModel.collectionDataArray) {
KNImageBrowserModel * imageBrowserModel = [[KNImageBrowserModel alloc] init];
imageBrowserModel.smallImageView = obj.imageView4small;
imageBrowserModel.urlStr = obj.originalAddress;
[self.viewModel.ImageBrowserModels addObject:imageBrowserModel];
}
}