一个简单易用的 iOS 图片浏览器
由于使用第三方库 SDWebImage 加载大图,因此需要另外导入 SDWebImage。
将文件夹中的所有文件 ZJPhotoController 拖动到工程中,导入主文件:#import "ZJPhotoController.h"
ZJPhotoBrowser *photoBrowser = [[ZJPhotoBrowser alloc] init];
photoBrowser.delegate = self;
[photoBrowser showWithSelectedIndex:tap.view.tag];
1.需要显示的图片数量
-(NSUInteger)numberOfPhotosInPhotoBrowser:(ZJPhotoBrowser *)photoBrowser{
return _picsArray.count;
}
2.返回需要显示的图片对应的 Photo 实例,通过 Photo 类指定大图的 URL,以及原始的图片视图
- (ZJPhoto *)photoBrowser:(ZJPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index {
ZJPhoto *zjPhoto = [[ZJPhoto alloc] init];
zjPhoto.srcImageView = _viewArray[index];
zjPhoto.url = [NSURL URLWithString:_picsArray[index]];
return zjPhoto;
}
//返回长按的事件,默认有保存图片
- (NSArray<ZJAction *> *)longPressActionsInPhotoBrowser:(ZJPhotoBrowser *)photoBrowser image:(UIImage *)image{
ZJAction* action = [[ZJAction alloc] initWithTitle:@"自定义" action:^{
NSLog(@"img%@", image);
}];
return @[action];
}
由于默认添加了保存图片的方法。因此需要在 Plist 文件中添加 "Privacy - Photo Library Usage Description" 的 key 来获取相册的权限。value 随你填,例如:"是否允许此 App 访问你的相册?"
如果在使用中遇到任何问题或建议,请提问,我会尽快处理。如果帮助到你,你懂的