在最近項目中遇到實現朋友圈的照片查看,當是自己寫了,就是在scrollview上加手勢實現,但是感覺就是不好,于是就找了個第三方,實現了。
實現的功能:
1、單次點擊到照片瀏覽,在此單次點擊退出瀏覽
2、進入照片瀏覽后雙擊放大、在此雙擊縮小
3、捏合放大縮小
4、照片的index顯示
5、照片的保存到本地沙盒
還有其他功能可以自己發現。。。
請看這塊:其實就是在集合視圖的點擊方法里面,
1.#import "UIImageView+WebCache.h"
2.#import "SDPhotoBrowser/SDPhotoBrowser.h"(這個是查看頭文件)
2.在點擊方法中寫如下方法,
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
//初始化照片查看
SDPhotoBrowser *photoBrowser = [[SDPhotoBrowser alloc] init];
//遵循代理
photoBrowser.delegate = self;
//傳入第幾個照片
photoBrowser.currentImageIndex = indexPath.item;
//總共幾個照片
photoBrowser.imageCount = self.imageArray.count;
//放集合視圖的容器視圖
photoBrowser.sourceImagesContainerView =self.collectionView;
//讓照片查看顯示
[photoBrowser show];
}```
// 返回臨時占位圖片(即原來的小圖)
- (UIImage *)photoBrowser:(SDPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index
{
return [UIImage imageNamed:@"placeHoderImage"];
}
// 返回高質量圖片的url
-
(NSURL *)photoBrowser:(SDPhotoBrowser *)browser highQualityImageURLForIndex:(NSInteger)index {
return self.imageArray[index];
}