├── collectionView的首页 ├── Assets.xcassets │ ├── Contents.json │ ├── Found │ │ ├── Contents.json │ │ ├── selectView_all.imageset │ │ │ ├── selectView_all.png │ │ │ └── Contents.json │ │ ├── selectView_food.imageset │ │ │ ├── selectView_food.png │ │ │ └── Contents.json │ │ ├── selectView_shop.imageset │ │ │ ├── selectView_shop.png │ │ │ └── Contents.json │ │ ├── selectView_trip.imageset │ │ │ ├── selectView_trip.png │ │ │ └── Contents.json │ │ ├── selectView_cancel.imageset │ │ │ ├── selectView_cancel.png │ │ │ └── Contents.json │ │ ├── selectView_lesure.imageset │ │ │ ├── selectView_lesure.png │ │ │ └── Contents.json │ │ ├── selectView_default.imageset │ │ │ ├── selectView_default.png │ │ │ └── Contents.json │ │ ├── selectView_activity.imageset │ │ │ ├── selectView_activity.png │ │ │ └── Contents.json │ │ ├── selectView_area_all.imageset │ │ │ ├── selectView_area_all.png │ │ │ └── Contents.json │ │ ├── selectView_sort_hot.imageset │ │ │ ├── selectView_sort_hot.png │ │ │ └── Contents.json │ │ ├── selectView_sort_new.imageset │ │ │ ├── selectView_sort_new.png │ │ │ └── Contents.json │ │ ├── selectView_area_nearby.imageset │ │ │ ├── selectView_area_nearby.png │ │ │ └── Contents.json │ │ ├── selectView_sort_nearby.imageset │ │ │ ├── selectView_sort_nearby.png │ │ │ └── Contents.json │ │ ├── selectView_area_default.imageset │ │ │ ├── selectView_area_default.png │ │ │ └── Contents.json │ │ └── selectView_sort_default.imageset │ │ │ ├── selectView_sort_default.png │ │ │ └── Contents.json │ ├── HomeView │ │ ├── Contents.json │ │ ├── neargb.imageset │ │ │ ├── neargb.png │ │ │ └── Contents.json │ │ ├── taoge.imageset │ │ │ ├── taoge@2x.png │ │ │ └── Contents.json │ │ ├── index_navigation_nearby.imageset │ │ │ ├── index_navigation_nearby.png │ │ │ └── Contents.json │ │ └── discoverNav_collectionHeart.imageset │ │ │ ├── discoverNav_collectionHeart.png │ │ │ └── Contents.json │ ├── LeftView │ │ ├── Contents.json │ │ ├── home.imageset │ │ │ ├── home@2x.png │ │ │ └── Contents.json │ │ ├── sina.imageset │ │ │ ├── sina@2x.png │ │ │ └── Contents.json │ │ ├── bgImage.imageset │ │ │ ├── bgImage.png │ │ │ └── Contents.json │ │ ├── city_up.imageset │ │ │ ├── city_up.png │ │ │ └── Contents.json │ │ ├── found.imageset │ │ │ ├── found@2x.png │ │ │ └── Contents.json │ │ ├── message.imageset │ │ │ ├── message@2x.png │ │ │ └── Contents.json │ │ ├── seting.imageset │ │ │ ├── seting@2x.png │ │ │ └── Contents.json │ │ ├── unLogin.imageset │ │ │ ├── unLogin@2x.png │ │ │ └── Contents.json │ │ ├── weixin.imageset │ │ │ ├── weixin@2x.png │ │ │ └── Contents.json │ │ ├── city_down.imageset │ │ │ ├── city_down.png │ │ │ └── Contents.json │ │ ├── homeSeletced.imageset │ │ │ ├── homeSeletced@2x.png │ │ │ └── Contents.json │ │ ├── foundSelected.imageset │ │ │ ├── foundSelected@2x.png │ │ │ └── Contents.json │ │ ├── setingSelected.imageset │ │ │ ├── setingSelected@2x.png │ │ │ └── Contents.json │ │ └── messageSelected.imageset │ │ │ ├── messageSelected@2x.png │ │ │ └── Contents.json │ ├── Other │ │ ├── Contents.json │ │ ├── bg.imageset │ │ │ ├── bg.jpg │ │ │ └── Contents.json │ │ ├── back.imageset │ │ │ ├── back@2x.png │ │ │ └── Contents.json │ │ ├── btn_share_normal.imageset │ │ │ ├── btn_share_normal.png │ │ │ └── Contents.json │ │ ├── recomend_btn_gone.imageset │ │ │ ├── recomend_btn_gone.png │ │ │ └── Contents.json │ │ ├── search_icon_white.imageset │ │ │ ├── search_icon_white.png │ │ │ └── Contents.json │ │ └── artcleList_btn_info.imageset │ │ │ ├── artcleList_btn_info.png │ │ │ └── Contents.json │ └── AppIcon.appiconset │ │ └── Contents.json ├── Other │ ├── JHNavController.h │ ├── UIImage+Image.h │ ├── UIColor+HexColor.h │ ├── JHNavController.m │ ├── UIImage+Image.m │ ├── PrefixHeader.pch │ └── UIColor+HexColor.m ├── ViewController.h ├── collectionView___.xcdatamodeld │ ├── .xccurrentversion │ └── collectionView___.xcdatamodel │ │ └── contents ├── JHBodyCell.h ├── View │ ├── JHHeaderFlowLayout.h │ ├── JHHeaderReusableView.h │ ├── JHHeaderReusableView.m │ ├── JHHeaderReusableView.xib │ └── JHHeaderFlowLayout.m ├── main.m ├── Model │ ├── JHBodyModel.m │ ├── JHBodyModel.h │ ├── JHHomeModel.h │ └── JHHomeModel.m ├── AppDelegate.h ├── JHBodyCell.m ├── Info.plist ├── Base.lproj │ ├── Main.storyboard │ └── LaunchScreen.storyboard ├── HomeDatas.plist ├── ViewController.m ├── JHBodyCell.xib └── AppDelegate.m ├── README.md ├── collectionView的首页.xcodeproj ├── xcuserdata │ └── laijinhao.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ ├── xcschememanagement.plist │ │ └── collectionView的首页.xcscheme └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ └── laijinhao.xcuserdatad │ └── UserInterfaceState.xcuserstate └── SDWebImage ├── UIImage+MultiFormat.h ├── SDWebImageOperation.h ├── UIImage+GIF.h ├── SDWebImageDecoder.h ├── UIImage+WebP.h ├── NSData+ImageContentType.h ├── UIView+WebCacheOperation.h ├── NSData+ImageContentType.m ├── SDWebImageCompat.m ├── SDWebImageCompat.h ├── UIView+WebCacheOperation.m ├── UIImage+WebP.m ├── SDWebImageDownloaderOperation.h ├── UIImage+MultiFormat.m ├── SDWebImageDecoder.m ├── SDWebImagePrefetcher.h ├── MKAnnotationView+WebCache.m ├── SDWebImagePrefetcher.m ├── UIImageView+HighlightedWebCache.h ├── UIImageView+HighlightedWebCache.m ├── UIImage+GIF.m ├── MKAnnotationView+WebCache.h ├── SDWebImageDownloader.h ├── SDImageCache.h ├── UIImageView+WebCache.h ├── SDWebImageManager.h └── SDWebImageDownloader.m /collectionView的首页/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/HomeView/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/LeftView/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Other/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # collectiongView头部漂浮是个开发中不错的效果 2 | 后续会抽出时间继续研究collectionView的其他牛逼效果,希望可以共同讨论 3 | 欢迎大家提出意见和star 4 | 在简书已经写了具体的用法: http://www.jianshu.com/p/f0a2a7a81c6f 5 | 6 | -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Other/bg.imageset/bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/Other/bg.imageset/bg.jpg -------------------------------------------------------------------------------- /collectionView的首页.xcodeproj/xcuserdata/laijinhao.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Other/back.imageset/back@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/Other/back.imageset/back@2x.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/HomeView/neargb.imageset/neargb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/HomeView/neargb.imageset/neargb.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/LeftView/home.imageset/home@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/LeftView/home.imageset/home@2x.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/LeftView/sina.imageset/sina@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/LeftView/sina.imageset/sina@2x.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/HomeView/taoge.imageset/taoge@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/HomeView/taoge.imageset/taoge@2x.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/LeftView/bgImage.imageset/bgImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/LeftView/bgImage.imageset/bgImage.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/LeftView/city_up.imageset/city_up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/LeftView/city_up.imageset/city_up.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/LeftView/found.imageset/found@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/LeftView/found.imageset/found@2x.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/LeftView/message.imageset/message@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/LeftView/message.imageset/message@2x.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/LeftView/seting.imageset/seting@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/LeftView/seting.imageset/seting@2x.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/LeftView/unLogin.imageset/unLogin@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/LeftView/unLogin.imageset/unLogin@2x.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/LeftView/weixin.imageset/weixin@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/LeftView/weixin.imageset/weixin@2x.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/LeftView/city_down.imageset/city_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/LeftView/city_down.imageset/city_down.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/selectView_all.imageset/selectView_all.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/Found/selectView_all.imageset/selectView_all.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/selectView_food.imageset/selectView_food.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/Found/selectView_food.imageset/selectView_food.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/selectView_shop.imageset/selectView_shop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/Found/selectView_shop.imageset/selectView_shop.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/selectView_trip.imageset/selectView_trip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/Found/selectView_trip.imageset/selectView_trip.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/LeftView/homeSeletced.imageset/homeSeletced@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/LeftView/homeSeletced.imageset/homeSeletced@2x.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/LeftView/foundSelected.imageset/foundSelected@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/LeftView/foundSelected.imageset/foundSelected@2x.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Other/btn_share_normal.imageset/btn_share_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/Other/btn_share_normal.imageset/btn_share_normal.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/selectView_cancel.imageset/selectView_cancel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/Found/selectView_cancel.imageset/selectView_cancel.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/selectView_lesure.imageset/selectView_lesure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/Found/selectView_lesure.imageset/selectView_lesure.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/LeftView/setingSelected.imageset/setingSelected@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/LeftView/setingSelected.imageset/setingSelected@2x.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Other/recomend_btn_gone.imageset/recomend_btn_gone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/Other/recomend_btn_gone.imageset/recomend_btn_gone.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Other/search_icon_white.imageset/search_icon_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/Other/search_icon_white.imageset/search_icon_white.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/selectView_default.imageset/selectView_default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/Found/selectView_default.imageset/selectView_default.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/LeftView/messageSelected.imageset/messageSelected@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/LeftView/messageSelected.imageset/messageSelected@2x.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/selectView_activity.imageset/selectView_activity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/Found/selectView_activity.imageset/selectView_activity.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/selectView_area_all.imageset/selectView_area_all.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/Found/selectView_area_all.imageset/selectView_area_all.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/selectView_sort_hot.imageset/selectView_sort_hot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/Found/selectView_sort_hot.imageset/selectView_sort_hot.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/selectView_sort_new.imageset/selectView_sort_new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/Found/selectView_sort_new.imageset/selectView_sort_new.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Other/artcleList_btn_info.imageset/artcleList_btn_info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/Other/artcleList_btn_info.imageset/artcleList_btn_info.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/selectView_area_nearby.imageset/selectView_area_nearby.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/Found/selectView_area_nearby.imageset/selectView_area_nearby.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/selectView_sort_nearby.imageset/selectView_sort_nearby.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/Found/selectView_sort_nearby.imageset/selectView_sort_nearby.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/selectView_area_default.imageset/selectView_area_default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/Found/selectView_area_default.imageset/selectView_area_default.png -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/selectView_sort_default.imageset/selectView_sort_default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/Found/selectView_sort_default.imageset/selectView_sort_default.png -------------------------------------------------------------------------------- /collectionView的首页.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/HomeView/index_navigation_nearby.imageset/index_navigation_nearby.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/HomeView/index_navigation_nearby.imageset/index_navigation_nearby.png -------------------------------------------------------------------------------- /collectionView的首页.xcodeproj/project.xcworkspace/xcuserdata/laijinhao.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页.xcodeproj/project.xcworkspace/xcuserdata/laijinhao.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/HomeView/discoverNav_collectionHeart.imageset/discoverNav_collectionHeart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reference/UICollectionViewHeaderFloat/master/collectionView的首页/Assets.xcassets/HomeView/discoverNav_collectionHeart.imageset/discoverNav_collectionHeart.png -------------------------------------------------------------------------------- /collectionView的首页/Other/JHNavController.h: -------------------------------------------------------------------------------- 1 | // 2 | // JHNavController.h 3 | // collectionView的首页 4 | // 5 | // Created by 会跳舞的狮子 on 16/5/4. 6 | // Copyright © 2016年 会跳舞的狮子 All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface JHNavController : UINavigationController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /collectionView的首页/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // collectionView的首页 4 | // 5 | // Created by 会跳舞的狮子 on 16/5/4. 6 | // Copyright © 2016年 会跳舞的狮子. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /collectionView的首页/collectionView___.xcdatamodeld/.xccurrentversion: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | _XCCurrentVersionName 6 | collectionView___.xcdatamodel 7 | 8 | 9 | -------------------------------------------------------------------------------- /SDWebImage/UIImage+MultiFormat.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+MultiFormat.h 3 | // SDWebImage 4 | // 5 | // Created by Olivier Poitrey on 07/06/13. 6 | // Copyright (c) 2013 Dailymotion. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIImage (MultiFormat) 12 | 13 | + (UIImage *)sd_imageWithData:(NSData *)data; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /collectionView的首页/Other/UIImage+Image.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+Image.h 3 | // 4 | // 5 | // Created by on 15/7/6. 6 | // Copyright (c) 2015年 . All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIImage (Image) 12 | 13 | 14 | // 根据颜色生成一张尺寸为1*1的相同颜色图片 15 | + (UIImage *)imageWithColor:(UIColor *)color; 16 | 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /collectionView的首页/JHBodyCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // JHBodyCell.h 3 | // collectionView的首页 4 | // 5 | // Created by会跳舞的狮子 on 16/5/4. 6 | // Copyright © 2016年 会跳舞的狮子. All rights reserved. 7 | // 8 | 9 | #import 10 | @class JHBodyModel; 11 | @interface JHBodyCell : UICollectionViewCell 12 | 13 | /** 模型属性 */ 14 | @property (nonatomic, strong) JHBodyModel *bodyModel; 15 | 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /collectionView的首页/View/JHHeaderFlowLayout.h: -------------------------------------------------------------------------------- 1 | // 2 | // JHHeaderFlowLayout.h 3 | // collectionView的首页 4 | // 5 | // Created by 会跳舞的狮子 on 16/5/4. 6 | // Copyright © 2016年 会跳舞的狮子. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface JHHeaderFlowLayout : UICollectionViewFlowLayout 12 | //默认为64.0, default is 64.0 13 | @property (nonatomic, assign) CGFloat naviHeight; 14 | @end 15 | -------------------------------------------------------------------------------- /SDWebImage/SDWebImageOperation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import 10 | 11 | @protocol SDWebImageOperation 12 | 13 | - (void)cancel; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /collectionView的首页/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // collectionView的首页 4 | // 5 | // Created by 会跳舞的狮子 on 16/5/4. 6 | // Copyright © 2016年 会跳舞的狮子. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /collectionView的首页/collectionView___.xcdatamodeld/collectionView___.xcdatamodel/contents: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /collectionView的首页/View/JHHeaderReusableView.h: -------------------------------------------------------------------------------- 1 | // 2 | // JHHeaderReusableView.h 3 | // collectionView的首页 4 | // 5 | // Created by 会跳舞的狮子 on 16/5/4. 6 | // Copyright © 2016年 会跳舞的狮子. All rights reserved. 7 | // 8 | 9 | #import 10 | @class JHHomeModel; 11 | @interface JHHeaderReusableView : UICollectionReusableView 12 | 13 | /** 模型属性 */ 14 | @property (nonatomic, strong) JHHomeModel *homeModel; 15 | 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /collectionView的首页/Other/UIColor+HexColor.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIColor+HexColor.h 3 | // HexColor 4 | // 5 | // Created by ZHANGHAI SHENG on 16/4/26. 6 | // Copyright © 2016年 ZHANGHAI SHENG. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIColor (HexColor) 12 | 13 | //随机颜色 14 | + (UIColor *)randomColor; 15 | 16 | //16进制自动转换RGB颜色 17 | + (UIColor *)colorWithHexString:(NSString *)stringToConvert; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Other/bg.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "bg.jpg", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Other/back.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "back@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/HomeView/neargb.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "neargb.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/HomeView/taoge.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "taoge@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/LeftView/bgImage.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "bgImage.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/LeftView/city_up.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "city_up.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/LeftView/found.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "found@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/LeftView/home.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "home@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/LeftView/sina.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "sina@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/LeftView/city_down.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "city_down.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/LeftView/message.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "message@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/LeftView/seting.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "seting@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/LeftView/unLogin.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "unLogin@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/LeftView/weixin.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "weixin@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/selectView_all.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "selectView_all.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/selectView_food.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "selectView_food.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/selectView_shop.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "selectView_shop.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/selectView_trip.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "selectView_trip.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/LeftView/foundSelected.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "foundSelected@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/LeftView/homeSeletced.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "homeSeletced@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Other/btn_share_normal.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "btn_share_normal.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/selectView_cancel.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "selectView_cancel.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/selectView_default.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "selectView_default.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/selectView_lesure.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "selectView_lesure.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/LeftView/messageSelected.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "messageSelected@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/LeftView/setingSelected.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "setingSelected@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Other/recomend_btn_gone.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "recomend_btn_gone.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Other/search_icon_white.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "search_icon_white.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /SDWebImage/UIImage+GIF.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+GIF.h 3 | // LBGIFImage 4 | // 5 | // Created by Laurin Brandner on 06.01.12. 6 | // Copyright (c) 2012 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIImage (GIF) 12 | 13 | + (UIImage *)sd_animatedGIFNamed:(NSString *)name; 14 | 15 | + (UIImage *)sd_animatedGIFWithData:(NSData *)data; 16 | 17 | - (UIImage *)sd_animatedImageByScalingAndCroppingToSize:(CGSize)size; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/selectView_activity.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "selectView_activity.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/selectView_area_all.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "selectView_area_all.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/selectView_sort_hot.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "selectView_sort_hot.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/selectView_sort_new.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "selectView_sort_new.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Other/artcleList_btn_info.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "artcleList_btn_info.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/selectView_area_default.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "selectView_area_default.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/selectView_area_nearby.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "selectView_area_nearby.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/selectView_sort_default.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "selectView_sort_default.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/Found/selectView_sort_nearby.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "selectView_sort_nearby.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/HomeView/index_navigation_nearby.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "index_navigation_nearby.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/HomeView/discoverNav_collectionHeart.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "discoverNav_collectionHeart.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /SDWebImage/SDWebImageDecoder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * Created by james on 9/28/11. 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | #import 12 | #import "SDWebImageCompat.h" 13 | 14 | @interface UIImage (ForceDecode) 15 | 16 | + (UIImage *)decodedImageWithImage:(UIImage *)image; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /collectionView的首页/Other/JHNavController.m: -------------------------------------------------------------------------------- 1 | // 2 | // JHNavController.m 3 | // collectionView的首页 4 | // 5 | // Created by 会跳舞的狮子 on 16/5/4. 6 | // Copyright © 2016年 会跳舞的狮子. All rights reserved. 7 | // 8 | 9 | #import "JHNavController.h" 10 | 11 | @interface JHNavController () 12 | 13 | @end 14 | 15 | @implementation JHNavController 16 | 17 | - (void)viewDidLoad { 18 | [super viewDidLoad]; 19 | 20 | //设置导航栏的背景图片 21 | // [self.navigationBar setBackgroundImage:[UIImage imageWithColor:[UIColor whiteColor]] forBarMetrics:UIBarMetricsDefault]; 22 | 23 | } 24 | 25 | 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /collectionView的首页/Model/JHBodyModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // JHBodyModel.m 3 | // collectionView的首页 4 | // 5 | // Created by 会跳舞的狮子 on 16/5/4. 6 | // Copyright © 2016年 会跳舞的狮子. All rights reserved. 7 | // 8 | 9 | #import "JHBodyModel.h" 10 | 11 | @implementation JHBodyModel 12 | + (instancetype)bodyWithDict:(NSDictionary *)dict 13 | { 14 | JHBodyModel *body = [[JHBodyModel alloc] init]; 15 | body.poi_name = dict[@"poi_name"]; 16 | body.imageURL = dict[@"imageURL"]; 17 | body.section_title = dict[@"section_title"]; 18 | body.fav_count = dict[@"fav_count"]; 19 | 20 | return body; 21 | } 22 | @end 23 | -------------------------------------------------------------------------------- /SDWebImage/UIImage+WebP.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+WebP.h 3 | // SDWebImage 4 | // 5 | // Created by Olivier Poitrey on 07/06/13. 6 | // Copyright (c) 2013 Dailymotion. All rights reserved. 7 | // 8 | 9 | #ifdef SD_WEBP 10 | 11 | #import 12 | 13 | // Fix for issue #416 Undefined symbols for architecture armv7 since WebP introduction when deploying to device 14 | void WebPInitPremultiplyNEON(void); 15 | 16 | void WebPInitUpsamplersNEON(void); 17 | 18 | void VP8DspInitNEON(void); 19 | 20 | @interface UIImage (WebP) 21 | 22 | + (UIImage *)sd_imageWithWebPData:(NSData *)data; 23 | 24 | @end 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /collectionView的首页/Model/JHBodyModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // JHBodyModel.h 3 | // collectionView的首页 4 | // 5 | // Created by 会跳舞的狮子 on 16/5/4. 6 | // Copyright © 2016年 会跳舞的狮子 All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface JHBodyModel : NSObject 12 | /** 每一行的标题 */ 13 | @property (nonatomic, copy) NSString *section_title; 14 | /** 图片的URL */ 15 | @property (nonatomic, copy) NSString *imageURL; 16 | /** 喜欢的个数 */ 17 | @property (nonatomic, copy) NSString *fav_count ; 18 | /** 行内名称 */ 19 | @property (nonatomic, copy) NSString *poi_name; 20 | 21 | + (instancetype)bodyWithDict:(NSDictionary *)dict; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /collectionView的首页/Model/JHHomeModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // JHHomeModel.h 3 | // collectionView的首页 4 | // 5 | // Created by 会跳舞的狮子 on 16/5/4. 6 | // Copyright © 2016年 会跳舞的狮子. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "JHBodyModel.h" 11 | @interface JHHomeModel : NSObject 12 | /** 颜色 */ 13 | @property (nonatomic, copy) NSString *color; 14 | 15 | /** 名字 */ 16 | @property (nonatomic, copy) NSString *tag_name; 17 | 18 | /** 精选个数 */ 19 | @property (nonatomic, copy) NSString *section_count; 20 | 21 | /** 数组 */ 22 | @property (nonatomic, strong) NSArray *body; 23 | 24 | + (instancetype)homeWithDict:(NSDictionary *)dict; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /collectionView的首页.xcodeproj/xcuserdata/laijinhao.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | collectionView的首页.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | FAD94A181CD99C9800B2EC54 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /SDWebImage/NSData+ImageContentType.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Fabrice Aneche on 06/01/14. 3 | // Copyright (c) 2014 Dailymotion. All rights reserved. 4 | // 5 | 6 | #import 7 | 8 | @interface NSData (ImageContentType) 9 | 10 | /** 11 | * Compute the content type for an image data 12 | * 13 | * @param data the input data 14 | * 15 | * @return the content type as string (i.e. image/jpeg, image/gif) 16 | */ 17 | + (NSString *)sd_contentTypeForImageData:(NSData *)data; 18 | 19 | @end 20 | 21 | 22 | @interface NSData (ImageContentTypeDeprecated) 23 | 24 | + (NSString *)contentTypeForImageData:(NSData *)data __deprecated_msg("Use `sd_contentTypeForImageData:`"); 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /collectionView的首页/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // collectionView的首页 4 | // 5 | // Created by 会跳舞的狮子 on 16/5/4. 6 | // Copyright © 2016年 会跳舞的狮子. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface AppDelegate : UIResponder 13 | 14 | @property (strong, nonatomic) UIWindow *window; 15 | 16 | @property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext; 17 | @property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel; 18 | @property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator; 19 | 20 | - (void)saveContext; 21 | - (NSURL *)applicationDocumentsDirectory; 22 | 23 | 24 | @end 25 | 26 | -------------------------------------------------------------------------------- /collectionView的首页/Model/JHHomeModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // JHHomeModel.m 3 | // collectionView的首页 4 | // 5 | // Created by 会跳舞的狮子 on 16/5/4. 6 | // Copyright © 2016年 会跳舞的狮子. All rights reserved. 7 | // 8 | 9 | #import "JHHomeModel.h" 10 | 11 | @implementation JHHomeModel 12 | + (instancetype)homeWithDict:(NSDictionary *)dict 13 | { 14 | JHHomeModel *home = [[JHHomeModel alloc] init]; 15 | home.tag_name = dict[@"tag_name"]; 16 | home.section_count = dict[@"section_count"]; 17 | home.color = dict[@"color"]; 18 | 19 | //字典数组转模型 20 | //保存模型的临时数组 21 | NSMutableArray *temp = [NSMutableArray array]; 22 | for (NSDictionary *dictArray in dict[@"body"]) { 23 | JHBodyModel *body = [JHBodyModel bodyWithDict:dictArray]; 24 | [temp addObject:body]; 25 | } 26 | home.body = temp; 27 | 28 | return home; 29 | 30 | } 31 | @end 32 | -------------------------------------------------------------------------------- /collectionView的首页/Other/UIImage+Image.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+Image.m 3 | // 4 | // 5 | // Created by on 15/7/6. 6 | // Copyright (c) 2015年 . All rights reserved. 7 | // 8 | 9 | #import "UIImage+Image.h" 10 | 11 | @implementation UIImage (Image) 12 | 13 | + (UIImage *)imageWithColor:(UIColor *)color 14 | { 15 | // 描述矩形 16 | CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); 17 | 18 | // 开启位图上下文 19 | UIGraphicsBeginImageContext(rect.size); 20 | // 获取位图上下文 21 | CGContextRef context = UIGraphicsGetCurrentContext(); 22 | // 使用color演示填充上下文 23 | CGContextSetFillColorWithColor(context, [color CGColor]); 24 | // 渲染上下文 25 | CGContextFillRect(context, rect); 26 | // 从上下文中获取图片 27 | UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext(); 28 | // 结束上下文 29 | UIGraphicsEndImageContext(); 30 | 31 | return theImage; 32 | } 33 | 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /collectionView的首页/View/JHHeaderReusableView.m: -------------------------------------------------------------------------------- 1 | // 2 | // JHHeaderReusableView.m 3 | // collectionView的首页 4 | // 5 | // Created by 会跳舞的狮子 on 16/5/4. 6 | // Copyright © 2016年 会跳舞的狮子. All rights reserved. 7 | // 8 | 9 | #import "JHHeaderReusableView.h" 10 | #import "JHHomeModel.h" 11 | @interface JHHeaderReusableView () 12 | @property (weak, nonatomic) IBOutlet UILabel *nameLabel; 13 | 14 | @property (weak, nonatomic) IBOutlet UILabel *countLabel; 15 | 16 | @end 17 | @implementation JHHeaderReusableView 18 | 19 | - (void)awakeFromNib { 20 | 21 | 22 | } 23 | 24 | /** 赋值 */ 25 | - (void)setHomeModel:(JHHomeModel *)homeModel 26 | { 27 | _homeModel = homeModel; 28 | 29 | self.nameLabel.text = homeModel.tag_name; 30 | self.countLabel.text = homeModel.section_count; 31 | 32 | self.backgroundColor = [UIColor colorWithHexString:homeModel.color]; 33 | // self.backgroundColor = JHRandomColor; 34 | } 35 | /** 点击头部视图的跳转 */ 36 | - (IBAction)clickHeader:(UIButton *)sender { 37 | 38 | JHLogFunc; 39 | } 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /collectionView的首页/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "3x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "2x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "3x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "57x57", 31 | "scale" : "1x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "57x57", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "iphone", 45 | "size" : "60x60", 46 | "scale" : "3x" 47 | } 48 | ], 49 | "info" : { 50 | "version" : 1, 51 | "author" : "xcode" 52 | } 53 | } -------------------------------------------------------------------------------- /SDWebImage/UIView+WebCacheOperation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import 10 | #import "SDWebImageManager.h" 11 | 12 | @interface UIView (WebCacheOperation) 13 | 14 | /** 15 | * Set the image load operation (storage in a UIView based dictionary) 16 | * 17 | * @param operation the operation 18 | * @param key key for storing the operation 19 | */ 20 | - (void)sd_setImageLoadOperation:(id)operation forKey:(NSString *)key; 21 | 22 | /** 23 | * Cancel all operations for the current UIView and key 24 | * 25 | * @param key key for identifying the operations 26 | */ 27 | - (void)sd_cancelImageLoadOperationWithKey:(NSString *)key; 28 | 29 | /** 30 | * Just remove the operations corresponding to the current UIView and key without cancelling them 31 | * 32 | * @param key key for identifying the operations 33 | */ 34 | - (void)sd_removeImageLoadOperationWithKey:(NSString *)key; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /collectionView的首页/JHBodyCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // JHBodyCell.m 3 | // collectionView的首页 4 | // 5 | // Created by 会跳舞的狮子 on 16/5/4. 6 | // Copyright © 2016年 会跳舞的狮子. All rights reserved. 7 | // 8 | 9 | #import "JHBodyCell.h" 10 | #import "JHBodyModel.h" 11 | #import "UIImageView+WebCache.h" 12 | @interface JHBodyCell () 13 | 14 | @property (weak, nonatomic) IBOutlet UIImageView *imageV; 15 | @property (weak, nonatomic) IBOutlet UIButton *nameBtn; 16 | @property (weak, nonatomic) IBOutlet UIButton *countBtn; 17 | @property (weak, nonatomic) IBOutlet UILabel *titleLabel; 18 | 19 | 20 | @end 21 | @implementation JHBodyCell 22 | 23 | - (void)awakeFromNib { 24 | 25 | self.backgroundColor = JHRandomColor; 26 | } 27 | 28 | //collectionView重写Frame不能修改间距,它里面有修改间距的属性 29 | //- (void)setFrame:(CGRect)frame 30 | //{ 31 | // frame.origin.y -= 10; 32 | // 33 | // [super setFrame:frame]; 34 | // 35 | //} 36 | 37 | - (void)setBodyModel:(JHBodyModel *)bodyModel 38 | { 39 | _bodyModel = bodyModel; 40 | self.titleLabel.text = bodyModel.section_title; 41 | [self.nameBtn setTitle:bodyModel.poi_name forState:UIControlStateNormal]; 42 | [self.countBtn setTitle:bodyModel.fav_count forState:UIControlStateNormal]; 43 | 44 | NSURL *url = [NSURL URLWithString:bodyModel.imageURL]; 45 | [self.imageV sd_setImageWithURL:url]; 46 | } 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /collectionView的首页/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /SDWebImage/NSData+ImageContentType.m: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Fabrice Aneche on 06/01/14. 3 | // Copyright (c) 2014 Dailymotion. All rights reserved. 4 | // 5 | 6 | #import "NSData+ImageContentType.h" 7 | 8 | 9 | @implementation NSData (ImageContentType) 10 | 11 | + (NSString *)sd_contentTypeForImageData:(NSData *)data { 12 | uint8_t c; 13 | [data getBytes:&c length:1]; 14 | switch (c) { 15 | case 0xFF: 16 | return @"image/jpeg"; 17 | case 0x89: 18 | return @"image/png"; 19 | case 0x47: 20 | return @"image/gif"; 21 | case 0x49: 22 | case 0x4D: 23 | return @"image/tiff"; 24 | case 0x52: 25 | // R as RIFF for WEBP 26 | if ([data length] < 12) { 27 | return nil; 28 | } 29 | 30 | NSString *testString = [[NSString alloc] initWithData:[data subdataWithRange:NSMakeRange(0, 12)] encoding:NSASCIIStringEncoding]; 31 | if ([testString hasPrefix:@"RIFF"] && [testString hasSuffix:@"WEBP"]) { 32 | return @"image/webp"; 33 | } 34 | 35 | return nil; 36 | } 37 | return nil; 38 | } 39 | 40 | @end 41 | 42 | 43 | @implementation NSData (ImageContentTypeDeprecated) 44 | 45 | + (NSString *)contentTypeForImageData:(NSData *)data { 46 | return [self sd_contentTypeForImageData:data]; 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /collectionView的首页/Other/PrefixHeader.pch: -------------------------------------------------------------------------------- 1 | // 2 | // PrefixHeader.pch 3 | // collectionView的首页 4 | // 5 | // Created by 会跳舞的狮子 on 16/5/4. 6 | // Copyright © 2016年 会跳舞的狮子. All rights reserved. 7 | // 8 | 9 | #ifndef PrefixHeader_pch 10 | #define PrefixHeader_pch 11 | 12 | #import "UIColor+HexColor.h" 13 | #import "UIImage+Image.h" 14 | 15 | 16 | //日志输出 17 | #ifdef DEBUG //log 18 | #define JHLog(...) NSLog(__VA_ARGS__) 19 | // 方法输出 20 | #define JHLogFunc JHLog(@"%s", __func__) 21 | #else // 发布阶段-上线阶段:移除Log 22 | #define JHLog(...) 23 | #endif 24 | 25 | /** 将服务器返回的数据写成plist */ 26 | #define JHAFNWriteToPlist(filename) [responseObject writeToFile:[NSString stringWithFormat:@"/Users/laijinhao/Desktop/%@.plist", filename] atomically:YES]; 27 | 28 | //新特性界面跳转的通知 29 | #define kNewFeatureNotify @"newFeature2TabBar" 30 | //Home里面的每组头部点击跳转的通知 31 | #define kShark @"kHeader2Shark" 32 | //屏幕的高度和宽度 33 | #define ScreenWidth [UIScreen mainScreen].bounds.size.width 34 | #define ScreenHeight [UIScreen mainScreen].bounds.size.height 35 | //默认导航栏的高度 36 | #define JHNavHeight 64 37 | 38 | 39 | //颜色 40 | /** 随机色 */ 41 | #define JHRandomColor JHColor(arc4random_uniform(255), arc4random_uniform(255), arc4random_uniform(255)) 42 | 43 | #define JHARGBColor(a,r,g,b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)/255.0] 44 | 45 | // 46 | #define JHColor(r,g,b) JHARGBColor(255, (r), (g), (b)) 47 | 48 | //灰色 49 | #define JHGrayColor(v) JHColor((v),(v),(v)) 50 | #define JHCommonBgColor JHGrayColor(215); 51 | 52 | // 快速创建弱指针 53 | #define __weakSelf __weak typeof(self) weakSelf = self; 54 | 55 | 56 | 57 | #endif /* PrefixHeader_pch */ 58 | -------------------------------------------------------------------------------- /collectionView的首页/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /SDWebImage/SDWebImageCompat.m: -------------------------------------------------------------------------------- 1 | // 2 | // SDWebImageCompat.m 3 | // SDWebImage 4 | // 5 | // Created by Olivier Poitrey on 11/12/12. 6 | // Copyright (c) 2012 Dailymotion. All rights reserved. 7 | // 8 | 9 | #import "SDWebImageCompat.h" 10 | 11 | #if !__has_feature(objc_arc) 12 | #error SDWebImage is ARC only. Either turn on ARC for the project or use -fobjc-arc flag 13 | #endif 14 | 15 | inline UIImage *SDScaledImageForKey(NSString *key, UIImage *image) { 16 | if (!image) { 17 | return nil; 18 | } 19 | 20 | if ([image.images count] > 0) { 21 | NSMutableArray *scaledImages = [NSMutableArray array]; 22 | 23 | for (UIImage *tempImage in image.images) { 24 | [scaledImages addObject:SDScaledImageForKey(key, tempImage)]; 25 | } 26 | 27 | return [UIImage animatedImageWithImages:scaledImages duration:image.duration]; 28 | } 29 | else { 30 | if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) { 31 | CGFloat scale = 1; 32 | if (key.length >= 8) { 33 | NSRange range = [key rangeOfString:@"@2x."]; 34 | if (range.location != NSNotFound) { 35 | scale = 2.0; 36 | } 37 | 38 | range = [key rangeOfString:@"@3x."]; 39 | if (range.location != NSNotFound) { 40 | scale = 3.0; 41 | } 42 | } 43 | 44 | UIImage *scaledImage = [[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:image.imageOrientation]; 45 | image = scaledImage; 46 | } 47 | return image; 48 | } 49 | } 50 | 51 | NSString *const SDWebImageErrorDomain = @"SDWebImageErrorDomain"; 52 | -------------------------------------------------------------------------------- /collectionView的首页/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /SDWebImage/SDWebImageCompat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * (c) Jamie Pinkham 5 | * 6 | * For the full copyright and license information, please view the LICENSE 7 | * file that was distributed with this source code. 8 | */ 9 | 10 | #import 11 | 12 | #ifdef __OBJC_GC__ 13 | #error SDWebImage does not support Objective-C Garbage Collection 14 | #endif 15 | 16 | #if __IPHONE_OS_VERSION_MIN_REQUIRED != 20000 && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_5_0 17 | #error SDWebImage doesn't support Deployment Target version < 5.0 18 | #endif 19 | 20 | #if !TARGET_OS_IPHONE 21 | #import 22 | #ifndef UIImage 23 | #define UIImage NSImage 24 | #endif 25 | #ifndef UIImageView 26 | #define UIImageView NSImageView 27 | #endif 28 | #else 29 | 30 | #import 31 | 32 | #endif 33 | 34 | #ifndef NS_ENUM 35 | #define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type 36 | #endif 37 | 38 | #ifndef NS_OPTIONS 39 | #define NS_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type 40 | #endif 41 | 42 | #if OS_OBJECT_USE_OBJC 43 | #undef SDDispatchQueueRelease 44 | #undef SDDispatchQueueSetterSementics 45 | #define SDDispatchQueueRelease(q) 46 | #define SDDispatchQueueSetterSementics strong 47 | #else 48 | #undef SDDispatchQueueRelease 49 | #undef SDDispatchQueueSetterSementics 50 | #define SDDispatchQueueRelease(q) (dispatch_release(q)) 51 | #define SDDispatchQueueSetterSementics assign 52 | #endif 53 | 54 | extern UIImage *SDScaledImageForKey(NSString *key, UIImage *image); 55 | 56 | typedef void(^SDWebImageNoParamsBlock)(); 57 | 58 | extern NSString *const SDWebImageErrorDomain; 59 | 60 | #define dispatch_main_sync_safe(block)\ 61 | if ([NSThread isMainThread]) {\ 62 | block();\ 63 | } else {\ 64 | dispatch_sync(dispatch_get_main_queue(), block);\ 65 | } 66 | 67 | #define dispatch_main_async_safe(block)\ 68 | if ([NSThread isMainThread]) {\ 69 | block();\ 70 | } else {\ 71 | dispatch_async(dispatch_get_main_queue(), block);\ 72 | } 73 | -------------------------------------------------------------------------------- /SDWebImage/UIView+WebCacheOperation.m: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import "UIView+WebCacheOperation.h" 10 | #import "objc/runtime.h" 11 | 12 | static char loadOperationKey; 13 | 14 | @implementation UIView (WebCacheOperation) 15 | 16 | - (NSMutableDictionary *)operationDictionary { 17 | NSMutableDictionary *operations = objc_getAssociatedObject(self, &loadOperationKey); 18 | if (operations) { 19 | return operations; 20 | } 21 | operations = [NSMutableDictionary dictionary]; 22 | objc_setAssociatedObject(self, &loadOperationKey, operations, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 23 | return operations; 24 | } 25 | 26 | - (void)sd_setImageLoadOperation:(id)operation forKey:(NSString *)key { 27 | [self sd_cancelImageLoadOperationWithKey:key]; 28 | NSMutableDictionary *operationDictionary = [self operationDictionary]; 29 | [operationDictionary setObject:operation forKey:key]; 30 | } 31 | 32 | - (void)sd_cancelImageLoadOperationWithKey:(NSString *)key { 33 | // Cancel in progress downloader from queue 34 | NSMutableDictionary *operationDictionary = [self operationDictionary]; 35 | id operations = [operationDictionary objectForKey:key]; 36 | if (operations) { 37 | if ([operations isKindOfClass:[NSArray class]]) { 38 | for (id operation in operations) { 39 | if (operation) { 40 | [operation cancel]; 41 | } 42 | } 43 | } else if ([operations conformsToProtocol:@protocol(SDWebImageOperation)]){ 44 | [(id) operations cancel]; 45 | } 46 | [operationDictionary removeObjectForKey:key]; 47 | } 48 | } 49 | 50 | - (void)sd_removeImageLoadOperationWithKey:(NSString *)key { 51 | NSMutableDictionary *operationDictionary = [self operationDictionary]; 52 | [operationDictionary removeObjectForKey:key]; 53 | } 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /collectionView的首页/Other/UIColor+HexColor.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIColor+HexColor.m 3 | // HexColor 4 | // 5 | // Created by ZHANGHAI SHENG on 16/4/26. 6 | // Copyright © 2016年 ZHANGHAI SHENG. All rights reserved. 7 | // 8 | 9 | #import "UIColor+HexColor.h" 10 | 11 | @implementation UIColor (HexColor) 12 | 13 | 14 | //随机颜色 15 | + (UIColor *)randomColor{ 16 | CGFloat r = arc4random_uniform(256)/255.0; 17 | CGFloat g = arc4random_uniform(256)/255.0; 18 | CGFloat b = arc4random_uniform(256)/255.0; 19 | return [UIColor colorWithRed:r green:g blue:b alpha:1]; 20 | } 21 | 22 | 23 | /** 24 | * 16进制自动转换RGB颜色 25 | * 26 | * @param stringToConvert 传入16进制色值 27 | * 28 | * @return 返回iOS中支持的RGB值 29 | * 30 | * 注意:iOS中默认不支持16进制色值,但是在公司中或者UI美工一般都使用标准的16进制表示颜色, 31 | * 我们可以通过这个方法将美工给的16进制颜色进行转换就OK了 32 | * 33 | */ 34 | + (UIColor *)colorWithHexString:(NSString *)stringToConvert 35 | { 36 | NSString *cString = [[stringToConvert stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString]; 37 | 38 | // String should be 6 or 8 characters 39 | if ([cString length] < 6) return [UIColor whiteColor]; 40 | 41 | // strip 0X if it appears 42 | if ([cString hasPrefix:@"0X"]) cString = [cString substringFromIndex:2]; 43 | else if ([cString hasPrefix:@"#"]) cString = [cString substringFromIndex:1]; 44 | if ([cString length] != 6) return [UIColor whiteColor]; 45 | // Separate into r, g, b substrings 46 | NSRange range; 47 | range.location = 0; 48 | range.length = 2; 49 | NSString *rString = [cString substringWithRange:range]; 50 | 51 | range.location = 2; 52 | NSString *gString = [cString substringWithRange:range]; 53 | 54 | range.location = 4; 55 | NSString *bString = [cString substringWithRange:range]; 56 | 57 | // Scan values 58 | unsigned int r, g, b; 59 | [[NSScanner scannerWithString:rString] scanHexInt:&r]; 60 | [[NSScanner scannerWithString:gString] scanHexInt:&g]; 61 | [[NSScanner scannerWithString:bString] scanHexInt:&b]; 62 | 63 | return [UIColor colorWithRed:((float) r / 255.0f) 64 | green:((float) g / 255.0f) 65 | blue:((float) b / 255.0f) 66 | alpha:1.0f]; 67 | } 68 | 69 | 70 | @end 71 | -------------------------------------------------------------------------------- /SDWebImage/UIImage+WebP.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+WebP.m 3 | // SDWebImage 4 | // 5 | // Created by Olivier Poitrey on 07/06/13. 6 | // Copyright (c) 2013 Dailymotion. All rights reserved. 7 | // 8 | 9 | #ifdef SD_WEBP 10 | #import "UIImage+WebP.h" 11 | 12 | #if !COCOAPODS 13 | #import "webp/decode.h" 14 | #else 15 | #import "libwebp/webp/decode.h" 16 | #endif 17 | 18 | // Callback for CGDataProviderRelease 19 | static void FreeImageData(void *info, const void *data, size_t size) 20 | { 21 | free((void *)data); 22 | } 23 | 24 | @implementation UIImage (WebP) 25 | 26 | + (UIImage *)sd_imageWithWebPData:(NSData *)data { 27 | WebPDecoderConfig config; 28 | if (!WebPInitDecoderConfig(&config)) { 29 | return nil; 30 | } 31 | 32 | if (WebPGetFeatures(data.bytes, data.length, &config.input) != VP8_STATUS_OK) { 33 | return nil; 34 | } 35 | 36 | config.output.colorspace = config.input.has_alpha ? MODE_rgbA : MODE_RGB; 37 | config.options.use_threads = 1; 38 | 39 | // Decode the WebP image data into a RGBA value array. 40 | if (WebPDecode(data.bytes, data.length, &config) != VP8_STATUS_OK) { 41 | return nil; 42 | } 43 | 44 | int width = config.input.width; 45 | int height = config.input.height; 46 | if (config.options.use_scaling) { 47 | width = config.options.scaled_width; 48 | height = config.options.scaled_height; 49 | } 50 | 51 | // Construct a UIImage from the decoded RGBA value array. 52 | CGDataProviderRef provider = 53 | CGDataProviderCreateWithData(NULL, config.output.u.RGBA.rgba, config.output.u.RGBA.size, FreeImageData); 54 | CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB(); 55 | CGBitmapInfo bitmapInfo = config.input.has_alpha ? kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast : 0; 56 | size_t components = config.input.has_alpha ? 4 : 3; 57 | CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault; 58 | CGImageRef imageRef = CGImageCreate(width, height, 8, components * 8, components * width, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent); 59 | 60 | CGColorSpaceRelease(colorSpaceRef); 61 | CGDataProviderRelease(provider); 62 | 63 | UIImage *image = [[UIImage alloc] initWithCGImage:imageRef]; 64 | CGImageRelease(imageRef); 65 | 66 | return image; 67 | } 68 | 69 | @end 70 | 71 | #if !COCOAPODS 72 | // Functions to resolve some undefined symbols when using WebP and force_load flag 73 | void WebPInitPremultiplyNEON(void) {} 74 | void WebPInitUpsamplersNEON(void) {} 75 | void VP8DspInitNEON(void) {} 76 | #endif 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /SDWebImage/SDWebImageDownloaderOperation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import 10 | #import "SDWebImageDownloader.h" 11 | #import "SDWebImageOperation.h" 12 | 13 | extern NSString *const SDWebImageDownloadStartNotification; 14 | extern NSString *const SDWebImageDownloadReceiveResponseNotification; 15 | extern NSString *const SDWebImageDownloadStopNotification; 16 | extern NSString *const SDWebImageDownloadFinishNotification; 17 | 18 | @interface SDWebImageDownloaderOperation : NSOperation 19 | 20 | /** 21 | * The request used by the operation's connection. 22 | */ 23 | @property (strong, nonatomic, readonly) NSURLRequest *request; 24 | 25 | 26 | @property (assign, nonatomic) BOOL shouldDecompressImages; 27 | 28 | /** 29 | * Whether the URL connection should consult the credential storage for authenticating the connection. `YES` by default. 30 | * 31 | * This is the value that is returned in the `NSURLConnectionDelegate` method `-connectionShouldUseCredentialStorage:`. 32 | */ 33 | @property (nonatomic, assign) BOOL shouldUseCredentialStorage; 34 | 35 | /** 36 | * The credential used for authentication challenges in `-connection:didReceiveAuthenticationChallenge:`. 37 | * 38 | * This will be overridden by any shared credentials that exist for the username or password of the request URL, if present. 39 | */ 40 | @property (nonatomic, strong) NSURLCredential *credential; 41 | 42 | /** 43 | * The SDWebImageDownloaderOptions for the receiver. 44 | */ 45 | @property (assign, nonatomic, readonly) SDWebImageDownloaderOptions options; 46 | 47 | /** 48 | * The expected size of data. 49 | */ 50 | @property (assign, nonatomic) NSInteger expectedSize; 51 | 52 | /** 53 | * The response returned by the operation's connection. 54 | */ 55 | @property (strong, nonatomic) NSURLResponse *response; 56 | 57 | /** 58 | * Initializes a `SDWebImageDownloaderOperation` object 59 | * 60 | * @see SDWebImageDownloaderOperation 61 | * 62 | * @param request the URL request 63 | * @param options downloader options 64 | * @param progressBlock the block executed when a new chunk of data arrives. 65 | * @note the progress block is executed on a background queue 66 | * @param completedBlock the block executed when the download is done. 67 | * @note the completed block is executed on the main queue for success. If errors are found, there is a chance the block will be executed on a background queue 68 | * @param cancelBlock the block executed if the download (operation) is cancelled 69 | * 70 | * @return the initialized instance 71 | */ 72 | - (id)initWithRequest:(NSURLRequest *)request 73 | options:(SDWebImageDownloaderOptions)options 74 | progress:(SDWebImageDownloaderProgressBlock)progressBlock 75 | completed:(SDWebImageDownloaderCompletedBlock)completedBlock 76 | cancelled:(SDWebImageNoParamsBlock)cancelBlock; 77 | 78 | @end 79 | -------------------------------------------------------------------------------- /SDWebImage/UIImage+MultiFormat.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+MultiFormat.m 3 | // SDWebImage 4 | // 5 | // Created by Olivier Poitrey on 07/06/13. 6 | // Copyright (c) 2013 Dailymotion. All rights reserved. 7 | // 8 | 9 | #import "UIImage+MultiFormat.h" 10 | #import "UIImage+GIF.h" 11 | #import "NSData+ImageContentType.h" 12 | #import 13 | 14 | #ifdef SD_WEBP 15 | #import "UIImage+WebP.h" 16 | #endif 17 | 18 | @implementation UIImage (MultiFormat) 19 | 20 | + (UIImage *)sd_imageWithData:(NSData *)data { 21 | if (!data) { 22 | return nil; 23 | } 24 | 25 | UIImage *image; 26 | NSString *imageContentType = [NSData sd_contentTypeForImageData:data]; 27 | if ([imageContentType isEqualToString:@"image/gif"]) { 28 | image = [UIImage sd_animatedGIFWithData:data]; 29 | } 30 | #ifdef SD_WEBP 31 | else if ([imageContentType isEqualToString:@"image/webp"]) 32 | { 33 | image = [UIImage sd_imageWithWebPData:data]; 34 | } 35 | #endif 36 | else { 37 | image = [[UIImage alloc] initWithData:data]; 38 | UIImageOrientation orientation = [self sd_imageOrientationFromImageData:data]; 39 | if (orientation != UIImageOrientationUp) { 40 | image = [UIImage imageWithCGImage:image.CGImage 41 | scale:image.scale 42 | orientation:orientation]; 43 | } 44 | } 45 | 46 | 47 | return image; 48 | } 49 | 50 | 51 | +(UIImageOrientation)sd_imageOrientationFromImageData:(NSData *)imageData { 52 | UIImageOrientation result = UIImageOrientationUp; 53 | CGImageSourceRef imageSource = CGImageSourceCreateWithData((__bridge CFDataRef)imageData, NULL); 54 | if (imageSource) { 55 | CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL); 56 | if (properties) { 57 | CFTypeRef val; 58 | int exifOrientation; 59 | val = CFDictionaryGetValue(properties, kCGImagePropertyOrientation); 60 | if (val) { 61 | CFNumberGetValue(val, kCFNumberIntType, &exifOrientation); 62 | result = [self sd_exifOrientationToiOSOrientation:exifOrientation]; 63 | } // else - if it's not set it remains at up 64 | CFRelease((CFTypeRef) properties); 65 | } else { 66 | //NSLog(@"NO PROPERTIES, FAIL"); 67 | } 68 | CFRelease(imageSource); 69 | } 70 | return result; 71 | } 72 | 73 | #pragma mark EXIF orientation tag converter 74 | // Convert an EXIF image orientation to an iOS one. 75 | // reference see here: http://sylvana.net/jpegcrop/exif_orientation.html 76 | + (UIImageOrientation) sd_exifOrientationToiOSOrientation:(int)exifOrientation { 77 | UIImageOrientation orientation = UIImageOrientationUp; 78 | switch (exifOrientation) { 79 | case 1: 80 | orientation = UIImageOrientationUp; 81 | break; 82 | 83 | case 3: 84 | orientation = UIImageOrientationDown; 85 | break; 86 | 87 | case 8: 88 | orientation = UIImageOrientationLeft; 89 | break; 90 | 91 | case 6: 92 | orientation = UIImageOrientationRight; 93 | break; 94 | 95 | case 2: 96 | orientation = UIImageOrientationUpMirrored; 97 | break; 98 | 99 | case 4: 100 | orientation = UIImageOrientationDownMirrored; 101 | break; 102 | 103 | case 5: 104 | orientation = UIImageOrientationLeftMirrored; 105 | break; 106 | 107 | case 7: 108 | orientation = UIImageOrientationRightMirrored; 109 | break; 110 | default: 111 | break; 112 | } 113 | return orientation; 114 | } 115 | 116 | 117 | 118 | @end 119 | -------------------------------------------------------------------------------- /collectionView的首页.xcodeproj/xcuserdata/laijinhao.xcuserdatad/xcschemes/collectionView的首页.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /SDWebImage/SDWebImageDecoder.m: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * Created by james on 9/28/11. 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | #import "SDWebImageDecoder.h" 12 | 13 | @implementation UIImage (ForceDecode) 14 | 15 | + (UIImage *)decodedImageWithImage:(UIImage *)image { 16 | // while downloading huge amount of images 17 | // autorelease the bitmap context 18 | // and all vars to help system to free memory 19 | // when there are memory warning. 20 | // on iOS7, do not forget to call 21 | // [[SDImageCache sharedImageCache] clearMemory]; 22 | 23 | if (image == nil) { // Prevent "CGBitmapContextCreateImage: invalid context 0x0" error 24 | return nil; 25 | } 26 | 27 | @autoreleasepool{ 28 | // do not decode animated images 29 | if (image.images != nil) { 30 | return image; 31 | } 32 | 33 | CGImageRef imageRef = image.CGImage; 34 | 35 | CGImageAlphaInfo alpha = CGImageGetAlphaInfo(imageRef); 36 | BOOL anyAlpha = (alpha == kCGImageAlphaFirst || 37 | alpha == kCGImageAlphaLast || 38 | alpha == kCGImageAlphaPremultipliedFirst || 39 | alpha == kCGImageAlphaPremultipliedLast); 40 | if (anyAlpha) { 41 | return image; 42 | } 43 | 44 | // current 45 | CGColorSpaceModel imageColorSpaceModel = CGColorSpaceGetModel(CGImageGetColorSpace(imageRef)); 46 | CGColorSpaceRef colorspaceRef = CGImageGetColorSpace(imageRef); 47 | 48 | BOOL unsupportedColorSpace = (imageColorSpaceModel == kCGColorSpaceModelUnknown || 49 | imageColorSpaceModel == kCGColorSpaceModelMonochrome || 50 | imageColorSpaceModel == kCGColorSpaceModelCMYK || 51 | imageColorSpaceModel == kCGColorSpaceModelIndexed); 52 | if (unsupportedColorSpace) { 53 | colorspaceRef = CGColorSpaceCreateDeviceRGB(); 54 | } 55 | 56 | size_t width = CGImageGetWidth(imageRef); 57 | size_t height = CGImageGetHeight(imageRef); 58 | NSUInteger bytesPerPixel = 4; 59 | NSUInteger bytesPerRow = bytesPerPixel * width; 60 | NSUInteger bitsPerComponent = 8; 61 | 62 | 63 | // kCGImageAlphaNone is not supported in CGBitmapContextCreate. 64 | // Since the original image here has no alpha info, use kCGImageAlphaNoneSkipLast 65 | // to create bitmap graphics contexts without alpha info. 66 | CGContextRef context = CGBitmapContextCreate(NULL, 67 | width, 68 | height, 69 | bitsPerComponent, 70 | bytesPerRow, 71 | colorspaceRef, 72 | kCGBitmapByteOrderDefault|kCGImageAlphaNoneSkipLast); 73 | 74 | // Draw the image into the context and retrieve the new bitmap image without alpha 75 | CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef); 76 | CGImageRef imageRefWithoutAlpha = CGBitmapContextCreateImage(context); 77 | UIImage *imageWithoutAlpha = [UIImage imageWithCGImage:imageRefWithoutAlpha 78 | scale:image.scale 79 | orientation:image.imageOrientation]; 80 | 81 | if (unsupportedColorSpace) { 82 | CGColorSpaceRelease(colorspaceRef); 83 | } 84 | 85 | CGContextRelease(context); 86 | CGImageRelease(imageRefWithoutAlpha); 87 | 88 | return imageWithoutAlpha; 89 | } 90 | } 91 | 92 | @end 93 | -------------------------------------------------------------------------------- /SDWebImage/SDWebImagePrefetcher.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import 10 | #import "SDWebImageManager.h" 11 | 12 | @class SDWebImagePrefetcher; 13 | 14 | @protocol SDWebImagePrefetcherDelegate 15 | 16 | @optional 17 | 18 | /** 19 | * Called when an image was prefetched. 20 | * 21 | * @param imagePrefetcher The current image prefetcher 22 | * @param imageURL The image url that was prefetched 23 | * @param finishedCount The total number of images that were prefetched (successful or not) 24 | * @param totalCount The total number of images that were to be prefetched 25 | */ 26 | - (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didPrefetchURL:(NSURL *)imageURL finishedCount:(NSUInteger)finishedCount totalCount:(NSUInteger)totalCount; 27 | 28 | /** 29 | * Called when all images are prefetched. 30 | * @param imagePrefetcher The current image prefetcher 31 | * @param totalCount The total number of images that were prefetched (whether successful or not) 32 | * @param skippedCount The total number of images that were skipped 33 | */ 34 | - (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didFinishWithTotalCount:(NSUInteger)totalCount skippedCount:(NSUInteger)skippedCount; 35 | 36 | @end 37 | 38 | typedef void(^SDWebImagePrefetcherProgressBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfTotalUrls); 39 | typedef void(^SDWebImagePrefetcherCompletionBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfSkippedUrls); 40 | 41 | /** 42 | * Prefetch some URLs in the cache for future use. Images are downloaded in low priority. 43 | */ 44 | @interface SDWebImagePrefetcher : NSObject 45 | 46 | /** 47 | * The web image manager 48 | */ 49 | @property (strong, nonatomic, readonly) SDWebImageManager *manager; 50 | 51 | /** 52 | * Maximum number of URLs to prefetch at the same time. Defaults to 3. 53 | */ 54 | @property (nonatomic, assign) NSUInteger maxConcurrentDownloads; 55 | 56 | /** 57 | * SDWebImageOptions for prefetcher. Defaults to SDWebImageLowPriority. 58 | */ 59 | @property (nonatomic, assign) SDWebImageOptions options; 60 | 61 | /** 62 | * Queue options for Prefetcher. Defaults to Main Queue. 63 | */ 64 | @property (nonatomic, assign) dispatch_queue_t prefetcherQueue; 65 | 66 | @property (weak, nonatomic) id delegate; 67 | 68 | /** 69 | * Return the global image prefetcher instance. 70 | */ 71 | + (SDWebImagePrefetcher *)sharedImagePrefetcher; 72 | 73 | /** 74 | * Allows you to instantiate a prefetcher with any arbitrary image manager. 75 | */ 76 | - (id)initWithImageManager:(SDWebImageManager *)manager; 77 | 78 | /** 79 | * Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching, 80 | * currently one image is downloaded at a time, 81 | * and skips images for failed downloads and proceed to the next image in the list 82 | * 83 | * @param urls list of URLs to prefetch 84 | */ 85 | - (void)prefetchURLs:(NSArray *)urls; 86 | 87 | /** 88 | * Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching, 89 | * currently one image is downloaded at a time, 90 | * and skips images for failed downloads and proceed to the next image in the list 91 | * 92 | * @param urls list of URLs to prefetch 93 | * @param progressBlock block to be called when progress updates; 94 | * first parameter is the number of completed (successful or not) requests, 95 | * second parameter is the total number of images originally requested to be prefetched 96 | * @param completionBlock block to be called when prefetching is completed 97 | * first param is the number of completed (successful or not) requests, 98 | * second parameter is the number of skipped requests 99 | */ 100 | - (void)prefetchURLs:(NSArray *)urls progress:(SDWebImagePrefetcherProgressBlock)progressBlock completed:(SDWebImagePrefetcherCompletionBlock)completionBlock; 101 | 102 | /** 103 | * Remove and cancel queued list 104 | */ 105 | - (void)cancelPrefetching; 106 | 107 | 108 | @end 109 | -------------------------------------------------------------------------------- /collectionView的首页/HomeDatas.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | color 7 | 9778f0 8 | tag_name 9 | 周末必去活动 10 | section_count 11 | 26个精选 12 | body 13 | 14 | 15 | section_title 16 | 童年女神樱桃小丸子25周年特展 17 | imageURL 18 | http://img.chengmi.com/cm/dafb3464-3dcc-4994-874a-ca78e40538b3 19 | fav_count 20 | 23 21 | poi_name 22 | 樱桃小丸子25周年博览会 23 | 24 | 25 | section_title 26 | 夏日相约斑马周末市集 27 | imageURL 28 | http://img.chengmi.com/cm/5088440a-a240-4deb-908a-39e8dfc6c6d5 29 | fav_count 30 | 333 31 | poi_name 32 | 斑马书店" 33 | 34 | 35 | section_title 36 | 百分百巴黎的建筑学 37 | imageURL 38 | http://img.chengmi.com/cm/1e25be24-78a0-4afb-8cf0-55dc70af7fa5 39 | fav_count 40 | 246 41 | poi_name 42 | 法国文化中心 43 | 44 | 45 | section_title 46 | 穿越时空去和白雪公主玩耍 47 | imageURL 48 | http://img.chengmi.com/cm/8160d58c-7270-490e-b214-4fddb3109d1b 49 | fav_count 50 | 443 51 | poi_name 52 | 北京apm购物中心" 53 | 54 | 55 | 56 | 57 | color 58 | 36d4a2 59 | tag_name 60 | 新开张 61 | section_count 62 | 21个新店速递 63 | body 64 | 65 | 66 | section_title 67 | 五道口最地道的宁夏酿皮肉夹馍 68 | imageURL 69 | http://img.chengmi.com/cm/4bf1a71a-62ba-410a-b3d0-72ef0d118dd0 70 | fav_count 71 | 254 72 | poi_name 73 | 难得馍糊 74 | 75 | 76 | section_title 77 | 慢火细炖8小时的精致牛肉浓汤面 78 | imageURL 79 | http://img.chengmi.com/cm/311a5954-db7b-454a-a702-ce8b13eddd3d 80 | fav_count 81 | 274 82 | poi_name 83 | 然面 84 | 85 | 86 | section_title 87 | 给你个预兆邂逅一杯好咖啡 88 | imageURL 89 | http://img.chengmi.com/cm/699f7d95-1e2d-4d82-a5ed-8b865677ff6b 90 | fav_count 91 | 1156 92 | poi_name 93 | A.omen Cafe&Bar 94 | 95 | 96 | 97 | 98 | color 99 | fc6c54 100 | tag_name 101 | 美妙下午茶 102 | section_count 103 | 23个心水之选 104 | body 105 | 106 | 107 | section_title 108 | 复古工业风的蛋糕后花园 109 | imageURL 110 | http://img.chengmi.com/cm/f7f4db22-8d1f-46e4-8188-7c06f238ad81 111 | fav_count 112 | 23 113 | poi_name 114 | JARDIN DES GATEAUX 蛋糕花园(工体店) 115 | 116 | 117 | section_title 118 | 798露台上的摩登芝士 119 | imageURL 120 | http://img.chengmi.com/cm/3cf57ee9-8698-48c2-98fb-88cc0b8c27a0 121 | fav_count 122 | 102 123 | poi_name 124 | 摩登芝士咖啡馆 125 | 126 | 127 | section_title 128 | 像王一样用餐考究的下午茶 129 | imageURL 130 | http://img.chengmi.com/cm/240857bc-cde1-485c-a808-41afaedd2ace 131 | fav_count 132 | 246 133 | poi_name 134 | 王的下午茶 135 | 136 | 137 | section_title 138 | 关于爱与梦想的杯子蛋糕家 139 | imageURL 140 | http://img.chengmi.com/cm/add662ea-9d32-4723-bbf4-badb146d6cb1 141 | fav_count 142 | 981 143 | poi_name 144 | 杯子蛋糕家Cupcake Philosopher 145 | 146 | 147 | section_title 148 | 全职妈妈的爱心私家下午茶点 149 | imageURL 150 | http://img.chengmi.com/cm/cdd71fd6-46e7-49bd-bf53-46853f184938 151 | fav_count 152 | 436 153 | poi_name 154 | Ivy's Bakery 155 | 156 | 157 | 158 | 159 | 160 | -------------------------------------------------------------------------------- /collectionView的首页/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // collectionView的首页 4 | // 5 | // Created by 会跳舞的狮子 on 16/5/4. 6 | // Copyright © 2016年 会跳舞的狮子. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "JHBodyCell.h" 11 | #import "JHBodyModel.h" 12 | #import "JHHomeModel.h" 13 | #import "JHHeaderReusableView.h" 14 | #import "JHHeaderFlowLayout.h" 15 | #define ScreenW [UIScreen mainScreen].bounds.size.width 16 | #define ScreenH [UIScreen mainScreen].bounds.size.height 17 | 18 | @interface ViewController () 19 | /** collectionView */ 20 | @property (nonatomic,weak) UICollectionView *collectionView; 21 | /** 保存模型属性的数组 */ 22 | @property (nonatomic, strong) NSMutableArray *bodyArray; 23 | 24 | @end 25 | 26 | @implementation ViewController 27 | static NSString *const kBodyID = @"JHBodyCell"; 28 | static NSString *const kHeaderID = @"JHHeaderReusableView"; 29 | 30 | 31 | #pragma mark - 懒加载 32 | - (NSMutableArray *)bodyArray 33 | { 34 | if (!_bodyArray) { 35 | 36 | //保存模型的数组 37 | NSMutableArray *temp = [NSMutableArray array]; 38 | //字典转模型 39 | NSArray *dictArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"HomeDatas" ofType:@"plist"]]; 40 | for (NSDictionary *dict in dictArray) { 41 | JHHomeModel *home = [JHHomeModel homeWithDict:dict]; 42 | [temp addObject:home]; 43 | } 44 | _bodyArray = temp; 45 | } 46 | 47 | return _bodyArray; 48 | } 49 | - (void)viewDidLoad { 50 | [super viewDidLoad]; 51 | 52 | //设置导航栏 53 | [self setupNav]; 54 | 55 | //设置collectionView 56 | [self setupCollection]; 57 | } 58 | 59 | /** 设置导航栏 */ 60 | - (void)setupNav 61 | { 62 | self.navigationItem.title = @"collectionView的头部视图漂浮"; 63 | 64 | 65 | self.navigationController.navigationBar.translucent = NO; 66 | } 67 | 68 | /* 设置collectionView */ 69 | - (void)setupCollection 70 | { 71 | //布局 72 | JHHeaderFlowLayout *layout = [[JHHeaderFlowLayout alloc] init]; 73 | 74 | layout.itemSize = CGSizeMake(ScreenW, 150); 75 | layout.minimumInteritemSpacing = 0; 76 | layout.minimumLineSpacing = 10; 77 | //设置头部视图的尺寸 78 | layout.headerReferenceSize = CGSizeMake(ScreenW, ScreenH * 0.085); 79 | UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout]; 80 | collectionView.showsVerticalScrollIndicator = NO; 81 | // self.automaticallyAdjustsScrollViewInsets = NO; 82 | collectionView.bounces = NO; 83 | collectionView.delegate = self; 84 | collectionView.dataSource = self; 85 | 86 | self.collectionView = collectionView; 87 | [self.view addSubview:collectionView]; 88 | 89 | //注册 90 | [self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([JHBodyCell class]) bundle:nil] forCellWithReuseIdentifier:kBodyID]; 91 | //注册头部视图 92 | [self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([JHHeaderReusableView class]) bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kHeaderID]; 93 | 94 | } 95 | 96 | /** 让状态栏隐藏 */ 97 | //- (BOOL)prefersStatusBarHidden 98 | //{ 99 | // return YES; 100 | //} 101 | 102 | 103 | #pragma mark - UICollectionViewDataSource 104 | /** 返回有多少组 */ 105 | - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView 106 | { 107 | return self.bodyArray.count; 108 | 109 | } 110 | 111 | /** 返回每组有多少个item */ 112 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 113 | { 114 | 115 | //每组的模型 116 | JHHomeModel *home = self.bodyArray[section]; 117 | 118 | return home.body.count; 119 | 120 | } 121 | /** 返回每个item的具体内容 */ 122 | - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 123 | { 124 | JHBodyCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kBodyID forIndexPath:indexPath]; 125 | 126 | //组模型 127 | JHHomeModel *home = self.bodyArray[indexPath.section]; 128 | 129 | //行模型 130 | JHBodyModel *body = home.body[indexPath.row]; 131 | 132 | cell.bodyModel = body; 133 | 134 | return cell; 135 | } 136 | 137 | 138 | #pragma mark - UICollectionViewDelegate 139 | //点击collectionView的item的时候调用 140 | - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 141 | { 142 | JHLogFunc; 143 | 144 | } 145 | 146 | #pragma mark - 头部或者尾部视图 147 | - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath 148 | { 149 | //如果是头部视图 150 | if (kind == UICollectionElementKindSectionHeader) { 151 | JHHeaderReusableView *headerRV = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:kHeaderID forIndexPath:indexPath]; 152 | headerRV.homeModel = self.bodyArray[indexPath.section]; 153 | return headerRV; 154 | 155 | }else 156 | { 157 | return nil; 158 | } 159 | 160 | } 161 | 162 | 163 | 164 | @end 165 | -------------------------------------------------------------------------------- /SDWebImage/MKAnnotationView+WebCache.m: -------------------------------------------------------------------------------- 1 | // 2 | // MKAnnotationView+WebCache.m 3 | // SDWebImage 4 | // 5 | // Created by Olivier Poitrey on 14/03/12. 6 | // Copyright (c) 2012 Dailymotion. All rights reserved. 7 | // 8 | 9 | #import "MKAnnotationView+WebCache.h" 10 | #import "objc/runtime.h" 11 | #import "UIView+WebCacheOperation.h" 12 | 13 | static char imageURLKey; 14 | 15 | @implementation MKAnnotationView (WebCache) 16 | 17 | - (NSURL *)sd_imageURL { 18 | return objc_getAssociatedObject(self, &imageURLKey); 19 | } 20 | 21 | - (void)sd_setImageWithURL:(NSURL *)url { 22 | [self sd_setImageWithURL:url placeholderImage:nil options:0 completed:nil]; 23 | } 24 | 25 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder { 26 | [self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:nil]; 27 | } 28 | 29 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { 30 | [self sd_setImageWithURL:url placeholderImage:placeholder options:options completed:nil]; 31 | } 32 | 33 | - (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock { 34 | [self sd_setImageWithURL:url placeholderImage:nil options:0 completed:completedBlock]; 35 | } 36 | 37 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock { 38 | [self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:completedBlock]; 39 | } 40 | 41 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { 42 | [self sd_cancelCurrentImageLoad]; 43 | 44 | objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 45 | self.image = placeholder; 46 | 47 | if (url) { 48 | __weak __typeof(self)wself = self; 49 | id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { 50 | if (!wself) return; 51 | dispatch_main_sync_safe(^{ 52 | __strong MKAnnotationView *sself = wself; 53 | if (!sself) return; 54 | if (image) { 55 | sself.image = image; 56 | } 57 | if (completedBlock && finished) { 58 | completedBlock(image, error, cacheType, url); 59 | } 60 | }); 61 | }]; 62 | [self sd_setImageLoadOperation:operation forKey:@"MKAnnotationViewImage"]; 63 | } else { 64 | dispatch_main_async_safe(^{ 65 | NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; 66 | if (completedBlock) { 67 | completedBlock(nil, error, SDImageCacheTypeNone, url); 68 | } 69 | }); 70 | } 71 | } 72 | 73 | - (void)sd_cancelCurrentImageLoad { 74 | [self sd_cancelImageLoadOperationWithKey:@"MKAnnotationViewImage"]; 75 | } 76 | 77 | @end 78 | 79 | 80 | @implementation MKAnnotationView (WebCacheDeprecated) 81 | 82 | - (NSURL *)imageURL { 83 | return [self sd_imageURL]; 84 | } 85 | 86 | - (void)setImageWithURL:(NSURL *)url { 87 | [self sd_setImageWithURL:url placeholderImage:nil options:0 completed:nil]; 88 | } 89 | 90 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder { 91 | [self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:nil]; 92 | } 93 | 94 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { 95 | [self sd_setImageWithURL:url placeholderImage:placeholder options:options completed:nil]; 96 | } 97 | 98 | - (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock { 99 | [self sd_setImageWithURL:url placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 100 | if (completedBlock) { 101 | completedBlock(image, error, cacheType); 102 | } 103 | }]; 104 | } 105 | 106 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock { 107 | [self sd_setImageWithURL:url placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 108 | if (completedBlock) { 109 | completedBlock(image, error, cacheType); 110 | } 111 | }]; 112 | } 113 | 114 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { 115 | [self sd_setImageWithURL:url placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 116 | if (completedBlock) { 117 | completedBlock(image, error, cacheType); 118 | } 119 | }]; 120 | } 121 | 122 | - (void)cancelCurrentImageLoad { 123 | [self sd_cancelCurrentImageLoad]; 124 | } 125 | 126 | @end 127 | -------------------------------------------------------------------------------- /SDWebImage/SDWebImagePrefetcher.m: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import "SDWebImagePrefetcher.h" 10 | 11 | @interface SDWebImagePrefetcher () 12 | 13 | @property (strong, nonatomic) SDWebImageManager *manager; 14 | @property (strong, nonatomic) NSArray *prefetchURLs; 15 | @property (assign, nonatomic) NSUInteger requestedCount; 16 | @property (assign, nonatomic) NSUInteger skippedCount; 17 | @property (assign, nonatomic) NSUInteger finishedCount; 18 | @property (assign, nonatomic) NSTimeInterval startedTime; 19 | @property (copy, nonatomic) SDWebImagePrefetcherCompletionBlock completionBlock; 20 | @property (copy, nonatomic) SDWebImagePrefetcherProgressBlock progressBlock; 21 | 22 | @end 23 | 24 | @implementation SDWebImagePrefetcher 25 | 26 | + (SDWebImagePrefetcher *)sharedImagePrefetcher { 27 | static dispatch_once_t once; 28 | static id instance; 29 | dispatch_once(&once, ^{ 30 | instance = [self new]; 31 | }); 32 | return instance; 33 | } 34 | 35 | - (id)init { 36 | return [self initWithImageManager:[SDWebImageManager new]]; 37 | } 38 | 39 | - (id)initWithImageManager:(SDWebImageManager *)manager { 40 | if ((self = [super init])) { 41 | _manager = manager; 42 | _options = SDWebImageLowPriority; 43 | _prefetcherQueue = dispatch_get_main_queue(); 44 | self.maxConcurrentDownloads = 3; 45 | } 46 | return self; 47 | } 48 | 49 | - (void)setMaxConcurrentDownloads:(NSUInteger)maxConcurrentDownloads { 50 | self.manager.imageDownloader.maxConcurrentDownloads = maxConcurrentDownloads; 51 | } 52 | 53 | - (NSUInteger)maxConcurrentDownloads { 54 | return self.manager.imageDownloader.maxConcurrentDownloads; 55 | } 56 | 57 | - (void)startPrefetchingAtIndex:(NSUInteger)index { 58 | if (index >= self.prefetchURLs.count) return; 59 | self.requestedCount++; 60 | [self.manager downloadImageWithURL:self.prefetchURLs[index] options:self.options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { 61 | if (!finished) return; 62 | self.finishedCount++; 63 | 64 | if (image) { 65 | if (self.progressBlock) { 66 | self.progressBlock(self.finishedCount,[self.prefetchURLs count]); 67 | } 68 | } 69 | else { 70 | if (self.progressBlock) { 71 | self.progressBlock(self.finishedCount,[self.prefetchURLs count]); 72 | } 73 | // Add last failed 74 | self.skippedCount++; 75 | } 76 | if ([self.delegate respondsToSelector:@selector(imagePrefetcher:didPrefetchURL:finishedCount:totalCount:)]) { 77 | [self.delegate imagePrefetcher:self 78 | didPrefetchURL:self.prefetchURLs[index] 79 | finishedCount:self.finishedCount 80 | totalCount:self.prefetchURLs.count 81 | ]; 82 | } 83 | if (self.prefetchURLs.count > self.requestedCount) { 84 | dispatch_async(self.prefetcherQueue, ^{ 85 | [self startPrefetchingAtIndex:self.requestedCount]; 86 | }); 87 | } else if (self.finishedCount == self.requestedCount) { 88 | [self reportStatus]; 89 | if (self.completionBlock) { 90 | self.completionBlock(self.finishedCount, self.skippedCount); 91 | self.completionBlock = nil; 92 | } 93 | self.progressBlock = nil; 94 | } 95 | }]; 96 | } 97 | 98 | - (void)reportStatus { 99 | NSUInteger total = [self.prefetchURLs count]; 100 | if ([self.delegate respondsToSelector:@selector(imagePrefetcher:didFinishWithTotalCount:skippedCount:)]) { 101 | [self.delegate imagePrefetcher:self 102 | didFinishWithTotalCount:(total - self.skippedCount) 103 | skippedCount:self.skippedCount 104 | ]; 105 | } 106 | } 107 | 108 | - (void)prefetchURLs:(NSArray *)urls { 109 | [self prefetchURLs:urls progress:nil completed:nil]; 110 | } 111 | 112 | - (void)prefetchURLs:(NSArray *)urls progress:(SDWebImagePrefetcherProgressBlock)progressBlock completed:(SDWebImagePrefetcherCompletionBlock)completionBlock { 113 | [self cancelPrefetching]; // Prevent duplicate prefetch request 114 | self.startedTime = CFAbsoluteTimeGetCurrent(); 115 | self.prefetchURLs = urls; 116 | self.completionBlock = completionBlock; 117 | self.progressBlock = progressBlock; 118 | 119 | if (urls.count == 0) { 120 | if (completionBlock) { 121 | completionBlock(0,0); 122 | } 123 | } else { 124 | // Starts prefetching from the very first image on the list with the max allowed concurrency 125 | NSUInteger listCount = self.prefetchURLs.count; 126 | for (NSUInteger i = 0; i < self.maxConcurrentDownloads && self.requestedCount < listCount; i++) { 127 | [self startPrefetchingAtIndex:i]; 128 | } 129 | } 130 | } 131 | 132 | - (void)cancelPrefetching { 133 | self.prefetchURLs = nil; 134 | self.skippedCount = 0; 135 | self.requestedCount = 0; 136 | self.finishedCount = 0; 137 | [self.manager cancelAll]; 138 | } 139 | 140 | @end 141 | -------------------------------------------------------------------------------- /SDWebImage/UIImageView+HighlightedWebCache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import 10 | #import "SDWebImageCompat.h" 11 | #import "SDWebImageManager.h" 12 | 13 | /** 14 | * Integrates SDWebImage async downloading and caching of remote images with UIImageView for highlighted state. 15 | */ 16 | @interface UIImageView (HighlightedWebCache) 17 | 18 | /** 19 | * Set the imageView `highlightedImage` with an `url`. 20 | * 21 | * The download is asynchronous and cached. 22 | * 23 | * @param url The url for the image. 24 | */ 25 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url; 26 | 27 | /** 28 | * Set the imageView `highlightedImage` with an `url` and custom options. 29 | * 30 | * The download is asynchronous and cached. 31 | * 32 | * @param url The url for the image. 33 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. 34 | */ 35 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options; 36 | 37 | /** 38 | * Set the imageView `highlightedImage` with an `url`. 39 | * 40 | * The download is asynchronous and cached. 41 | * 42 | * @param url The url for the image. 43 | * @param completedBlock A block called when operation has been completed. This block has no return value 44 | * and takes the requested UIImage as first parameter. In case of error the image parameter 45 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 46 | * indicating if the image was retrieved from the local cache or from the network. 47 | * The fourth parameter is the original image url. 48 | */ 49 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock; 50 | 51 | /** 52 | * Set the imageView `highlightedImage` with an `url` and custom options. 53 | * 54 | * The download is asynchronous and cached. 55 | * 56 | * @param url The url for the image. 57 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. 58 | * @param completedBlock A block called when operation has been completed. This block has no return value 59 | * and takes the requested UIImage as first parameter. In case of error the image parameter 60 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 61 | * indicating if the image was retrieved from the local cache or from the network. 62 | * The fourth parameter is the original image url. 63 | */ 64 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; 65 | 66 | /** 67 | * Set the imageView `highlightedImage` with an `url` and custom options. 68 | * 69 | * The download is asynchronous and cached. 70 | * 71 | * @param url The url for the image. 72 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. 73 | * @param progressBlock A block called while image is downloading 74 | * @param completedBlock A block called when operation has been completed. This block has no return value 75 | * and takes the requested UIImage as first parameter. In case of error the image parameter 76 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 77 | * indicating if the image was retrieved from the local cache or from the network. 78 | * The fourth parameter is the original image url. 79 | */ 80 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock; 81 | 82 | /** 83 | * Cancel the current download 84 | */ 85 | - (void)sd_cancelCurrentHighlightedImageLoad; 86 | 87 | @end 88 | 89 | 90 | @interface UIImageView (HighlightedWebCacheDeprecated) 91 | 92 | - (void)setHighlightedImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:`"); 93 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:`"); 94 | - (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:completed:`"); 95 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:completed:`"); 96 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:progress:completed:`"); 97 | 98 | - (void)cancelCurrentHighlightedImageLoad __deprecated_msg("Use `sd_cancelCurrentHighlightedImageLoad`"); 99 | 100 | @end 101 | -------------------------------------------------------------------------------- /SDWebImage/UIImageView+HighlightedWebCache.m: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import "UIImageView+HighlightedWebCache.h" 10 | #import "UIView+WebCacheOperation.h" 11 | 12 | #define UIImageViewHighlightedWebCacheOperationKey @"highlightedImage" 13 | 14 | @implementation UIImageView (HighlightedWebCache) 15 | 16 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url { 17 | [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:nil]; 18 | } 19 | 20 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options { 21 | [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:nil]; 22 | } 23 | 24 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock { 25 | [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:completedBlock]; 26 | } 27 | 28 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { 29 | [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:completedBlock]; 30 | } 31 | 32 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock { 33 | [self sd_cancelCurrentHighlightedImageLoad]; 34 | 35 | if (url) { 36 | __weak __typeof(self)wself = self; 37 | id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { 38 | if (!wself) return; 39 | dispatch_main_sync_safe (^ 40 | { 41 | if (!wself) return; 42 | if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock) 43 | { 44 | completedBlock(image, error, cacheType, url); 45 | return; 46 | } 47 | else if (image) { 48 | wself.highlightedImage = image; 49 | [wself setNeedsLayout]; 50 | } 51 | if (completedBlock && finished) { 52 | completedBlock(image, error, cacheType, url); 53 | } 54 | }); 55 | }]; 56 | [self sd_setImageLoadOperation:operation forKey:UIImageViewHighlightedWebCacheOperationKey]; 57 | } else { 58 | dispatch_main_async_safe(^{ 59 | NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; 60 | if (completedBlock) { 61 | completedBlock(nil, error, SDImageCacheTypeNone, url); 62 | } 63 | }); 64 | } 65 | } 66 | 67 | - (void)sd_cancelCurrentHighlightedImageLoad { 68 | [self sd_cancelImageLoadOperationWithKey:UIImageViewHighlightedWebCacheOperationKey]; 69 | } 70 | 71 | @end 72 | 73 | 74 | @implementation UIImageView (HighlightedWebCacheDeprecated) 75 | 76 | - (void)setHighlightedImageWithURL:(NSURL *)url { 77 | [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:nil]; 78 | } 79 | 80 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options { 81 | [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:nil]; 82 | } 83 | 84 | - (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock { 85 | [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 86 | if (completedBlock) { 87 | completedBlock(image, error, cacheType); 88 | } 89 | }]; 90 | } 91 | 92 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { 93 | [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 94 | if (completedBlock) { 95 | completedBlock(image, error, cacheType); 96 | } 97 | }]; 98 | } 99 | 100 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock { 101 | [self sd_setHighlightedImageWithURL:url options:0 progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 102 | if (completedBlock) { 103 | completedBlock(image, error, cacheType); 104 | } 105 | }]; 106 | } 107 | 108 | - (void)cancelCurrentHighlightedImageLoad { 109 | [self sd_cancelCurrentHighlightedImageLoad]; 110 | } 111 | 112 | @end 113 | -------------------------------------------------------------------------------- /SDWebImage/UIImage+GIF.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+GIF.m 3 | // LBGIFImage 4 | // 5 | // Created by Laurin Brandner on 06.01.12. 6 | // Copyright (c) 2012 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import "UIImage+GIF.h" 10 | #import 11 | 12 | @implementation UIImage (GIF) 13 | 14 | + (UIImage *)sd_animatedGIFWithData:(NSData *)data { 15 | if (!data) { 16 | return nil; 17 | } 18 | 19 | CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL); 20 | 21 | size_t count = CGImageSourceGetCount(source); 22 | 23 | UIImage *animatedImage; 24 | 25 | if (count <= 1) { 26 | animatedImage = [[UIImage alloc] initWithData:data]; 27 | } 28 | else { 29 | NSMutableArray *images = [NSMutableArray array]; 30 | 31 | NSTimeInterval duration = 0.0f; 32 | 33 | for (size_t i = 0; i < count; i++) { 34 | CGImageRef image = CGImageSourceCreateImageAtIndex(source, i, NULL); 35 | if (!image) { 36 | continue; 37 | } 38 | 39 | duration += [self sd_frameDurationAtIndex:i source:source]; 40 | 41 | [images addObject:[UIImage imageWithCGImage:image scale:[UIScreen mainScreen].scale orientation:UIImageOrientationUp]]; 42 | 43 | CGImageRelease(image); 44 | } 45 | 46 | if (!duration) { 47 | duration = (1.0f / 10.0f) * count; 48 | } 49 | 50 | animatedImage = [UIImage animatedImageWithImages:images duration:duration]; 51 | } 52 | 53 | CFRelease(source); 54 | 55 | return animatedImage; 56 | } 57 | 58 | + (float)sd_frameDurationAtIndex:(NSUInteger)index source:(CGImageSourceRef)source { 59 | float frameDuration = 0.1f; 60 | CFDictionaryRef cfFrameProperties = CGImageSourceCopyPropertiesAtIndex(source, index, nil); 61 | NSDictionary *frameProperties = (__bridge NSDictionary *)cfFrameProperties; 62 | NSDictionary *gifProperties = frameProperties[(NSString *)kCGImagePropertyGIFDictionary]; 63 | 64 | NSNumber *delayTimeUnclampedProp = gifProperties[(NSString *)kCGImagePropertyGIFUnclampedDelayTime]; 65 | if (delayTimeUnclampedProp) { 66 | frameDuration = [delayTimeUnclampedProp floatValue]; 67 | } 68 | else { 69 | 70 | NSNumber *delayTimeProp = gifProperties[(NSString *)kCGImagePropertyGIFDelayTime]; 71 | if (delayTimeProp) { 72 | frameDuration = [delayTimeProp floatValue]; 73 | } 74 | } 75 | 76 | // Many annoying ads specify a 0 duration to make an image flash as quickly as possible. 77 | // We follow Firefox's behavior and use a duration of 100 ms for any frames that specify 78 | // a duration of <= 10 ms. See and 79 | // for more information. 80 | 81 | if (frameDuration < 0.011f) { 82 | frameDuration = 0.100f; 83 | } 84 | 85 | CFRelease(cfFrameProperties); 86 | return frameDuration; 87 | } 88 | 89 | + (UIImage *)sd_animatedGIFNamed:(NSString *)name { 90 | CGFloat scale = [UIScreen mainScreen].scale; 91 | 92 | if (scale > 1.0f) { 93 | NSString *retinaPath = [[NSBundle mainBundle] pathForResource:[name stringByAppendingString:@"@2x"] ofType:@"gif"]; 94 | 95 | NSData *data = [NSData dataWithContentsOfFile:retinaPath]; 96 | 97 | if (data) { 98 | return [UIImage sd_animatedGIFWithData:data]; 99 | } 100 | 101 | NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"gif"]; 102 | 103 | data = [NSData dataWithContentsOfFile:path]; 104 | 105 | if (data) { 106 | return [UIImage sd_animatedGIFWithData:data]; 107 | } 108 | 109 | return [UIImage imageNamed:name]; 110 | } 111 | else { 112 | NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"gif"]; 113 | 114 | NSData *data = [NSData dataWithContentsOfFile:path]; 115 | 116 | if (data) { 117 | return [UIImage sd_animatedGIFWithData:data]; 118 | } 119 | 120 | return [UIImage imageNamed:name]; 121 | } 122 | } 123 | 124 | - (UIImage *)sd_animatedImageByScalingAndCroppingToSize:(CGSize)size { 125 | if (CGSizeEqualToSize(self.size, size) || CGSizeEqualToSize(size, CGSizeZero)) { 126 | return self; 127 | } 128 | 129 | CGSize scaledSize = size; 130 | CGPoint thumbnailPoint = CGPointZero; 131 | 132 | CGFloat widthFactor = size.width / self.size.width; 133 | CGFloat heightFactor = size.height / self.size.height; 134 | CGFloat scaleFactor = (widthFactor > heightFactor) ? widthFactor : heightFactor; 135 | scaledSize.width = self.size.width * scaleFactor; 136 | scaledSize.height = self.size.height * scaleFactor; 137 | 138 | if (widthFactor > heightFactor) { 139 | thumbnailPoint.y = (size.height - scaledSize.height) * 0.5; 140 | } 141 | else if (widthFactor < heightFactor) { 142 | thumbnailPoint.x = (size.width - scaledSize.width) * 0.5; 143 | } 144 | 145 | NSMutableArray *scaledImages = [NSMutableArray array]; 146 | 147 | for (UIImage *image in self.images) { 148 | UIGraphicsBeginImageContextWithOptions(size, NO, 0.0); 149 | 150 | [image drawInRect:CGRectMake(thumbnailPoint.x, thumbnailPoint.y, scaledSize.width, scaledSize.height)]; 151 | UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 152 | 153 | [scaledImages addObject:newImage]; 154 | 155 | UIGraphicsEndImageContext(); 156 | } 157 | 158 | return [UIImage animatedImageWithImages:scaledImages duration:self.duration]; 159 | } 160 | 161 | @end 162 | -------------------------------------------------------------------------------- /collectionView的首页/View/JHHeaderReusableView.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 32 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /collectionView的首页/JHBodyCell.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 25 | 31 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /SDWebImage/MKAnnotationView+WebCache.h: -------------------------------------------------------------------------------- 1 | // 2 | // MKAnnotationView+WebCache.h 3 | // SDWebImage 4 | // 5 | // Created by Olivier Poitrey on 14/03/12. 6 | // Copyright (c) 2012 Dailymotion. All rights reserved. 7 | // 8 | 9 | #import "MapKit/MapKit.h" 10 | #import "SDWebImageManager.h" 11 | 12 | /** 13 | * Integrates SDWebImage async downloading and caching of remote images with MKAnnotationView. 14 | */ 15 | @interface MKAnnotationView (WebCache) 16 | 17 | /** 18 | * Get the current image URL. 19 | * 20 | * Note that because of the limitations of categories this property can get out of sync 21 | * if you use sd_setImage: directly. 22 | */ 23 | - (NSURL *)sd_imageURL; 24 | 25 | /** 26 | * Set the imageView `image` with an `url`. 27 | * 28 | * The download is asynchronous and cached. 29 | * 30 | * @param url The url for the image. 31 | */ 32 | - (void)sd_setImageWithURL:(NSURL *)url; 33 | 34 | /** 35 | * Set the imageView `image` with an `url` and a placeholder. 36 | * 37 | * The download is asynchronous and cached. 38 | * 39 | * @param url The url for the image. 40 | * @param placeholder The image to be set initially, until the image request finishes. 41 | * @see sd_setImageWithURL:placeholderImage:options: 42 | */ 43 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder; 44 | 45 | /** 46 | * Set the imageView `image` with an `url`, placeholder and custom options. 47 | * 48 | * The download is asynchronous and cached. 49 | * 50 | * @param url The url for the image. 51 | * @param placeholder The image to be set initially, until the image request finishes. 52 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. 53 | */ 54 | 55 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; 56 | 57 | /** 58 | * Set the imageView `image` with an `url`. 59 | * 60 | * The download is asynchronous and cached. 61 | * 62 | * @param url The url for the image. 63 | * @param completedBlock A block called when operation has been completed. This block has no return value 64 | * and takes the requested UIImage as first parameter. In case of error the image parameter 65 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 66 | * indicating if the image was retrieved from the local cache or from the network. 67 | * The fourth parameter is the original image url. 68 | */ 69 | - (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock; 70 | 71 | /** 72 | * Set the imageView `image` with an `url`, placeholder. 73 | * 74 | * The download is asynchronous and cached. 75 | * 76 | * @param url The url for the image. 77 | * @param placeholder The image to be set initially, until the image request finishes. 78 | * @param completedBlock A block called when operation has been completed. This block has no return value 79 | * and takes the requested UIImage as first parameter. In case of error the image parameter 80 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 81 | * indicating if the image was retrieved from the local cache or from the network. 82 | * The fourth parameter is the original image url. 83 | */ 84 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; 85 | 86 | /** 87 | * Set the imageView `image` with an `url`, placeholder and custom options. 88 | * 89 | * The download is asynchronous and cached. 90 | * 91 | * @param url The url for the image. 92 | * @param placeholder The image to be set initially, until the image request finishes. 93 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. 94 | * @param completedBlock A block called when operation has been completed. This block has no return value 95 | * and takes the requested UIImage as first parameter. In case of error the image parameter 96 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 97 | * indicating if the image was retrieved from the local cache or from the network. 98 | * The fourth parameter is the original image url. 99 | */ 100 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; 101 | 102 | /** 103 | * Cancel the current download 104 | */ 105 | - (void)sd_cancelCurrentImageLoad; 106 | 107 | @end 108 | 109 | 110 | @interface MKAnnotationView (WebCacheDeprecated) 111 | 112 | - (NSURL *)imageURL __deprecated_msg("Use `sd_imageURL`"); 113 | 114 | - (void)setImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:`"); 115 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:`"); 116 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:`"); 117 | 118 | - (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:completed:`"); 119 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:completed:`"); 120 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:completed:`"); 121 | 122 | - (void)cancelCurrentImageLoad __deprecated_msg("Use `sd_cancelCurrentImageLoad`"); 123 | 124 | @end 125 | -------------------------------------------------------------------------------- /collectionView的首页/View/JHHeaderFlowLayout.m: -------------------------------------------------------------------------------- 1 | // 2 | // JHHeaderFlowLayout.m 3 | // collectionView的首页 4 | // 5 | // Created by 会跳舞的狮子 on 16/5/4. 6 | // Copyright © 2016年 会跳舞的狮子. All rights reserved. 7 | // 8 | 9 | #import "JHHeaderFlowLayout.h" 10 | 11 | @implementation JHHeaderFlowLayout 12 | -(instancetype)init 13 | { 14 | self = [super init]; 15 | if (self) 16 | { 17 | _naviHeight = 0.0; 18 | } 19 | return self; 20 | } 21 | /* 22 | 23 | // 作用:返回指定区域的cell布局对象 24 | // 什么时候调用:指定新的区域的时候调用 25 | - (nullable NSArray<__kindof UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect 26 | 27 | */ 28 | - (NSArray *) layoutAttributesForElementsInRect:(CGRect)rect 29 | { 30 | //UICollectionViewLayoutAttributes:我称它为collectionView中的item(包括cell和header、footer这些)的《结构信息》 31 | //截取到父类所返回的数组(里面放的是当前屏幕所能展示的item的结构信息),并转化成不可变数组 32 | NSMutableArray *superArray = [[super layoutAttributesForElementsInRect:rect] mutableCopy]; 33 | 34 | //创建存索引的数组,无符号(正整数),无序(不能通过下标取值),不可重复(重复的话会自动过滤) 35 | NSMutableIndexSet *noneHeaderSections = [NSMutableIndexSet indexSet]; 36 | //遍历superArray,得到一个当前屏幕中所有的section数组 37 | for (UICollectionViewLayoutAttributes *attributes in superArray) 38 | { 39 | //如果当前的元素分类是一个cell,将cell所在的分区section加入数组,重复的话会自动过滤 40 | if (attributes.representedElementCategory == UICollectionElementCategoryCell) 41 | { 42 | [noneHeaderSections addIndex:attributes.indexPath.section]; 43 | } 44 | } 45 | 46 | //遍历superArray,将当前屏幕中拥有的header的section从数组中移除,得到一个当前屏幕中没有header的section数组 47 | //正常情况下,随着手指往上移,header脱离屏幕会被系统回收而cell尚在,也会触发该方法 48 | for (UICollectionViewLayoutAttributes *attributes in superArray) 49 | { 50 | //如果当前的元素是一个header,将header所在的section从数组中移除 51 | if ([attributes.representedElementKind isEqualToString:UICollectionElementKindSectionHeader]) 52 | { 53 | [noneHeaderSections removeIndex:attributes.indexPath.section]; 54 | } 55 | } 56 | 57 | //遍历当前屏幕中没有header的section数组 58 | [noneHeaderSections enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop){ 59 | 60 | //取到当前section中第一个item的indexPath 61 | NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:idx]; 62 | //获取当前section在正常情况下已经离开屏幕的header结构信息 63 | UICollectionViewLayoutAttributes *attributes = [self layoutAttributesForSupplementaryViewOfKind:UICollectionElementKindSectionHeader atIndexPath:indexPath]; 64 | 65 | //如果当前分区确实有因为离开屏幕而被系统回收的header 66 | if (attributes) 67 | { 68 | //将该header结构信息重新加入到superArray中去 69 | [superArray addObject:attributes]; 70 | } 71 | }]; 72 | 73 | //遍历superArray,改变header结构信息中的参数,使它可以在当前section还没完全离开屏幕的时候一直显示 74 | for (UICollectionViewLayoutAttributes *attributes in superArray) { 75 | 76 | //如果当前item是header 77 | if ([attributes.representedElementKind isEqualToString:UICollectionElementKindSectionHeader]) 78 | { 79 | //得到当前header所在分区的cell的数量 80 | NSInteger numberOfItemsInSection = [self.collectionView numberOfItemsInSection:attributes.indexPath.section]; 81 | //得到第一个item的indexPath 82 | NSIndexPath *firstItemIndexPath = [NSIndexPath indexPathForItem:0 inSection:attributes.indexPath.section]; 83 | //得到最后一个item的indexPath 84 | NSIndexPath *lastItemIndexPath = [NSIndexPath indexPathForItem:MAX(0, numberOfItemsInSection-1) inSection:attributes.indexPath.section]; 85 | //得到第一个item和最后一个item的结构信息 86 | UICollectionViewLayoutAttributes *firstItemAttributes, *lastItemAttributes; 87 | if (numberOfItemsInSection>0) 88 | { 89 | //cell有值,则获取第一个cell和最后一个cell的结构信息 90 | firstItemAttributes = [self layoutAttributesForItemAtIndexPath:firstItemIndexPath]; 91 | lastItemAttributes = [self layoutAttributesForItemAtIndexPath:lastItemIndexPath]; 92 | }else 93 | { 94 | //cell没值,就新建一个UICollectionViewLayoutAttributes 95 | firstItemAttributes = [UICollectionViewLayoutAttributes new]; 96 | //然后模拟出在当前分区中的唯一一个cell,cell在header的下面,高度为0,还与header隔着可能存在的sectionInset的top 97 | CGFloat y = CGRectGetMaxY(attributes.frame)+self.sectionInset.top; 98 | firstItemAttributes.frame = CGRectMake(0, y, 0, 0); 99 | //因为只有一个cell,所以最后一个cell等于第一个cell 100 | lastItemAttributes = firstItemAttributes; 101 | } 102 | 103 | //获取当前header的frame 104 | CGRect rect = attributes.frame; 105 | 106 | //当前的滑动距离 + 因为导航栏产生的偏移量,默认为64(如果app需求不同,需自己设置) 107 | CGFloat offset = self.collectionView.contentOffset.y + _naviHeight; 108 | //第一个cell的y值 - 当前header的高度 - 可能存在的sectionInset的top 109 | CGFloat headerY = firstItemAttributes.frame.origin.y - rect.size.height - self.sectionInset.top; 110 | 111 | //哪个大取哪个,保证header悬停 112 | //针对当前header基本上都是offset更加大,针对下一个header则会是headerY大,各自处理 113 | CGFloat maxY = MAX(offset,headerY); 114 | 115 | //最后一个cell的y值 + 最后一个cell的高度 + 可能存在的sectionInset的bottom - 当前header的高度 116 | //当当前section的footer或者下一个section的header接触到当前header的底部,计算出的headerMissingY即为有效值 117 | CGFloat headerMissingY = CGRectGetMaxY(lastItemAttributes.frame) + self.sectionInset.bottom - rect.size.height; 118 | 119 | //给rect的y赋新值,因为在最后消失的临界点要跟谁消失,所以取小 120 | rect.origin.y = MIN(maxY,headerMissingY); 121 | //给header的结构信息的frame重新赋值 122 | attributes.frame = rect; 123 | 124 | //如果按照正常情况下,header离开屏幕被系统回收,而header的层次关系又与cell相等,如果不去理会,会出现cell在header上面的情况 125 | //通过打印可以知道cell的层次关系zIndex数值为0,我们可以将header的zIndex设置成1,如果不放心,也可以将它设置成非常大,这里随便填了个7 126 | attributes.zIndex = 7; 127 | } 128 | } 129 | 130 | //转换回不可变数组,并返回 131 | return [superArray copy]; 132 | 133 | } 134 | 135 | //return YES;表示一旦滑动就实时调用上面这个layoutAttributesForElementsInRect:方法 136 | - (BOOL) shouldInvalidateLayoutForBoundsChange:(CGRect)newBound 137 | { 138 | return YES; 139 | } 140 | @end 141 | -------------------------------------------------------------------------------- /collectionView的首页/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // collectionView的首页 4 | // 5 | // Created by 会跳舞的狮子 on 16/5/4. 6 | // Copyright © 2016年 会跳舞的狮子. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "ViewController.h" 11 | #import "JHNavController.h" 12 | @interface AppDelegate () 13 | 14 | @end 15 | 16 | @implementation AppDelegate 17 | 18 | 19 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 20 | 21 | 22 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 23 | 24 | self.window.rootViewController = [[JHNavController alloc] initWithRootViewController:[ViewController new]]; 25 | 26 | [self.window makeKeyAndVisible]; 27 | 28 | 29 | 30 | return YES; 31 | } 32 | 33 | - (void)applicationWillResignActive:(UIApplication *)application { 34 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 35 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 36 | } 37 | 38 | - (void)applicationDidEnterBackground:(UIApplication *)application { 39 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 40 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 41 | } 42 | 43 | - (void)applicationWillEnterForeground:(UIApplication *)application { 44 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 45 | } 46 | 47 | - (void)applicationDidBecomeActive:(UIApplication *)application { 48 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 49 | } 50 | 51 | - (void)applicationWillTerminate:(UIApplication *)application { 52 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 53 | // Saves changes in the application's managed object context before the application terminates. 54 | [self saveContext]; 55 | } 56 | 57 | #pragma mark - Core Data stack 58 | 59 | @synthesize managedObjectContext = _managedObjectContext; 60 | @synthesize managedObjectModel = _managedObjectModel; 61 | @synthesize persistentStoreCoordinator = _persistentStoreCoordinator; 62 | 63 | - (NSURL *)applicationDocumentsDirectory { 64 | // The directory the application uses to store the Core Data store file. This code uses a directory named "--.collectionView___" in the application's documents directory. 65 | return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; 66 | } 67 | 68 | - (NSManagedObjectModel *)managedObjectModel { 69 | // The managed object model for the application. It is a fatal error for the application not to be able to find and load its model. 70 | if (_managedObjectModel != nil) { 71 | return _managedObjectModel; 72 | } 73 | NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"collectionView___" withExtension:@"momd"]; 74 | _managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; 75 | return _managedObjectModel; 76 | } 77 | 78 | - (NSPersistentStoreCoordinator *)persistentStoreCoordinator { 79 | // The persistent store coordinator for the application. This implementation creates and returns a coordinator, having added the store for the application to it. 80 | if (_persistentStoreCoordinator != nil) { 81 | return _persistentStoreCoordinator; 82 | } 83 | 84 | // Create the coordinator and store 85 | 86 | _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; 87 | NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"collectionView___.sqlite"]; 88 | NSError *error = nil; 89 | NSString *failureReason = @"There was an error creating or loading the application's saved data."; 90 | if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) { 91 | // Report any error we got. 92 | NSMutableDictionary *dict = [NSMutableDictionary dictionary]; 93 | dict[NSLocalizedDescriptionKey] = @"Failed to initialize the application's saved data"; 94 | dict[NSLocalizedFailureReasonErrorKey] = failureReason; 95 | dict[NSUnderlyingErrorKey] = error; 96 | error = [NSError errorWithDomain:@"YOUR_ERROR_DOMAIN" code:9999 userInfo:dict]; 97 | // Replace this with code to handle the error appropriately. 98 | // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 99 | NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 100 | abort(); 101 | } 102 | 103 | return _persistentStoreCoordinator; 104 | } 105 | 106 | 107 | - (NSManagedObjectContext *)managedObjectContext { 108 | // Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.) 109 | if (_managedObjectContext != nil) { 110 | return _managedObjectContext; 111 | } 112 | 113 | NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator]; 114 | if (!coordinator) { 115 | return nil; 116 | } 117 | _managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; 118 | [_managedObjectContext setPersistentStoreCoordinator:coordinator]; 119 | return _managedObjectContext; 120 | } 121 | 122 | #pragma mark - Core Data Saving support 123 | 124 | - (void)saveContext { 125 | NSManagedObjectContext *managedObjectContext = self.managedObjectContext; 126 | if (managedObjectContext != nil) { 127 | NSError *error = nil; 128 | if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) { 129 | // Replace this implementation with code to handle the error appropriately. 130 | // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 131 | NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 132 | abort(); 133 | } 134 | } 135 | } 136 | 137 | @end 138 | -------------------------------------------------------------------------------- /SDWebImage/SDWebImageDownloader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import 10 | #import "SDWebImageCompat.h" 11 | #import "SDWebImageOperation.h" 12 | 13 | typedef NS_OPTIONS(NSUInteger, SDWebImageDownloaderOptions) { 14 | SDWebImageDownloaderLowPriority = 1 << 0, 15 | SDWebImageDownloaderProgressiveDownload = 1 << 1, 16 | 17 | /** 18 | * By default, request prevent the use of NSURLCache. With this flag, NSURLCache 19 | * is used with default policies. 20 | */ 21 | SDWebImageDownloaderUseNSURLCache = 1 << 2, 22 | 23 | /** 24 | * Call completion block with nil image/imageData if the image was read from NSURLCache 25 | * (to be combined with `SDWebImageDownloaderUseNSURLCache`). 26 | */ 27 | 28 | SDWebImageDownloaderIgnoreCachedResponse = 1 << 3, 29 | /** 30 | * In iOS 4+, continue the download of the image if the app goes to background. This is achieved by asking the system for 31 | * extra time in background to let the request finish. If the background task expires the operation will be cancelled. 32 | */ 33 | 34 | SDWebImageDownloaderContinueInBackground = 1 << 4, 35 | 36 | /** 37 | * Handles cookies stored in NSHTTPCookieStore by setting 38 | * NSMutableURLRequest.HTTPShouldHandleCookies = YES; 39 | */ 40 | SDWebImageDownloaderHandleCookies = 1 << 5, 41 | 42 | /** 43 | * Enable to allow untrusted SSL certificates. 44 | * Useful for testing purposes. Use with caution in production. 45 | */ 46 | SDWebImageDownloaderAllowInvalidSSLCertificates = 1 << 6, 47 | 48 | /** 49 | * Put the image in the high priority queue. 50 | */ 51 | SDWebImageDownloaderHighPriority = 1 << 7, 52 | }; 53 | 54 | typedef NS_ENUM(NSInteger, SDWebImageDownloaderExecutionOrder) { 55 | /** 56 | * Default value. All download operations will execute in queue style (first-in-first-out). 57 | */ 58 | SDWebImageDownloaderFIFOExecutionOrder, 59 | 60 | /** 61 | * All download operations will execute in stack style (last-in-first-out). 62 | */ 63 | SDWebImageDownloaderLIFOExecutionOrder 64 | }; 65 | 66 | extern NSString *const SDWebImageDownloadStartNotification; 67 | extern NSString *const SDWebImageDownloadStopNotification; 68 | 69 | typedef void(^SDWebImageDownloaderProgressBlock)(NSInteger receivedSize, NSInteger expectedSize); 70 | 71 | typedef void(^SDWebImageDownloaderCompletedBlock)(UIImage *image, NSData *data, NSError *error, BOOL finished); 72 | 73 | typedef NSDictionary *(^SDWebImageDownloaderHeadersFilterBlock)(NSURL *url, NSDictionary *headers); 74 | 75 | /** 76 | * Asynchronous downloader dedicated and optimized for image loading. 77 | */ 78 | @interface SDWebImageDownloader : NSObject 79 | 80 | /** 81 | * Decompressing images that are downloaded and cached can improve performance but can consume lot of memory. 82 | * Defaults to YES. Set this to NO if you are experiencing a crash due to excessive memory consumption. 83 | */ 84 | @property (assign, nonatomic) BOOL shouldDecompressImages; 85 | 86 | @property (assign, nonatomic) NSInteger maxConcurrentDownloads; 87 | 88 | /** 89 | * Shows the current amount of downloads that still need to be downloaded 90 | */ 91 | @property (readonly, nonatomic) NSUInteger currentDownloadCount; 92 | 93 | 94 | /** 95 | * The timeout value (in seconds) for the download operation. Default: 15.0. 96 | */ 97 | @property (assign, nonatomic) NSTimeInterval downloadTimeout; 98 | 99 | 100 | /** 101 | * Changes download operations execution order. Default value is `SDWebImageDownloaderFIFOExecutionOrder`. 102 | */ 103 | @property (assign, nonatomic) SDWebImageDownloaderExecutionOrder executionOrder; 104 | 105 | /** 106 | * Singleton method, returns the shared instance 107 | * 108 | * @return global shared instance of downloader class 109 | */ 110 | + (SDWebImageDownloader *)sharedDownloader; 111 | 112 | /** 113 | * Set the default URL credential to be set for request operations. 114 | */ 115 | @property (strong, nonatomic) NSURLCredential *urlCredential; 116 | 117 | /** 118 | * Set username 119 | */ 120 | @property (strong, nonatomic) NSString *username; 121 | 122 | /** 123 | * Set password 124 | */ 125 | @property (strong, nonatomic) NSString *password; 126 | 127 | /** 128 | * Set filter to pick headers for downloading image HTTP request. 129 | * 130 | * This block will be invoked for each downloading image request, returned 131 | * NSDictionary will be used as headers in corresponding HTTP request. 132 | */ 133 | @property (nonatomic, copy) SDWebImageDownloaderHeadersFilterBlock headersFilter; 134 | 135 | /** 136 | * Set a value for a HTTP header to be appended to each download HTTP request. 137 | * 138 | * @param value The value for the header field. Use `nil` value to remove the header. 139 | * @param field The name of the header field to set. 140 | */ 141 | - (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field; 142 | 143 | /** 144 | * Returns the value of the specified HTTP header field. 145 | * 146 | * @return The value associated with the header field field, or `nil` if there is no corresponding header field. 147 | */ 148 | - (NSString *)valueForHTTPHeaderField:(NSString *)field; 149 | 150 | /** 151 | * Sets a subclass of `SDWebImageDownloaderOperation` as the default 152 | * `NSOperation` to be used each time SDWebImage constructs a request 153 | * operation to download an image. 154 | * 155 | * @param operationClass The subclass of `SDWebImageDownloaderOperation` to set 156 | * as default. Passing `nil` will revert to `SDWebImageDownloaderOperation`. 157 | */ 158 | - (void)setOperationClass:(Class)operationClass; 159 | 160 | /** 161 | * Creates a SDWebImageDownloader async downloader instance with a given URL 162 | * 163 | * The delegate will be informed when the image is finish downloaded or an error has happen. 164 | * 165 | * @see SDWebImageDownloaderDelegate 166 | * 167 | * @param url The URL to the image to download 168 | * @param options The options to be used for this download 169 | * @param progressBlock A block called repeatedly while the image is downloading 170 | * @param completedBlock A block called once the download is completed. 171 | * If the download succeeded, the image parameter is set, in case of error, 172 | * error parameter is set with the error. The last parameter is always YES 173 | * if SDWebImageDownloaderProgressiveDownload isn't use. With the 174 | * SDWebImageDownloaderProgressiveDownload option, this block is called 175 | * repeatedly with the partial image object and the finished argument set to NO 176 | * before to be called a last time with the full image and finished argument 177 | * set to YES. In case of error, the finished argument is always YES. 178 | * 179 | * @return A cancellable SDWebImageOperation 180 | */ 181 | - (id )downloadImageWithURL:(NSURL *)url 182 | options:(SDWebImageDownloaderOptions)options 183 | progress:(SDWebImageDownloaderProgressBlock)progressBlock 184 | completed:(SDWebImageDownloaderCompletedBlock)completedBlock; 185 | 186 | /** 187 | * Sets the download queue suspension state 188 | */ 189 | - (void)setSuspended:(BOOL)suspended; 190 | 191 | @end 192 | -------------------------------------------------------------------------------- /SDWebImage/SDImageCache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import 10 | #import "SDWebImageCompat.h" 11 | 12 | typedef NS_ENUM(NSInteger, SDImageCacheType) { 13 | /** 14 | * The image wasn't available the SDWebImage caches, but was downloaded from the web. 15 | */ 16 | SDImageCacheTypeNone, 17 | /** 18 | * The image was obtained from the disk cache. 19 | */ 20 | SDImageCacheTypeDisk, 21 | /** 22 | * The image was obtained from the memory cache. 23 | */ 24 | SDImageCacheTypeMemory 25 | }; 26 | 27 | typedef void(^SDWebImageQueryCompletedBlock)(UIImage *image, SDImageCacheType cacheType); 28 | 29 | typedef void(^SDWebImageCheckCacheCompletionBlock)(BOOL isInCache); 30 | 31 | typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger totalSize); 32 | 33 | /** 34 | * SDImageCache maintains a memory cache and an optional disk cache. Disk cache write operations are performed 35 | * asynchronous so it doesn’t add unnecessary latency to the UI. 36 | */ 37 | @interface SDImageCache : NSObject 38 | 39 | /** 40 | * Decompressing images that are downloaded and cached can improve performance but can consume lot of memory. 41 | * Defaults to YES. Set this to NO if you are experiencing a crash due to excessive memory consumption. 42 | */ 43 | @property (assign, nonatomic) BOOL shouldDecompressImages; 44 | 45 | /** 46 | * disable iCloud backup [defaults to YES] 47 | */ 48 | @property (assign, nonatomic) BOOL shouldDisableiCloud; 49 | 50 | /** 51 | * use memory cache [defaults to YES] 52 | */ 53 | @property (assign, nonatomic) BOOL shouldCacheImagesInMemory; 54 | 55 | /** 56 | * The maximum "total cost" of the in-memory image cache. The cost function is the number of pixels held in memory. 57 | */ 58 | @property (assign, nonatomic) NSUInteger maxMemoryCost; 59 | 60 | /** 61 | * The maximum number of objects the cache should hold. 62 | */ 63 | @property (assign, nonatomic) NSUInteger maxMemoryCountLimit; 64 | 65 | /** 66 | * The maximum length of time to keep an image in the cache, in seconds 67 | */ 68 | @property (assign, nonatomic) NSInteger maxCacheAge; 69 | 70 | /** 71 | * The maximum size of the cache, in bytes. 72 | */ 73 | @property (assign, nonatomic) NSUInteger maxCacheSize; 74 | 75 | /** 76 | * Returns global shared cache instance 77 | * 78 | * @return SDImageCache global instance 79 | */ 80 | + (SDImageCache *)sharedImageCache; 81 | 82 | /** 83 | * Init a new cache store with a specific namespace 84 | * 85 | * @param ns The namespace to use for this cache store 86 | */ 87 | - (id)initWithNamespace:(NSString *)ns; 88 | 89 | /** 90 | * Init a new cache store with a specific namespace and directory 91 | * 92 | * @param ns The namespace to use for this cache store 93 | * @param directory Directory to cache disk images in 94 | */ 95 | - (id)initWithNamespace:(NSString *)ns diskCacheDirectory:(NSString *)directory; 96 | 97 | -(NSString *)makeDiskCachePath:(NSString*)fullNamespace; 98 | 99 | /** 100 | * Add a read-only cache path to search for images pre-cached by SDImageCache 101 | * Useful if you want to bundle pre-loaded images with your app 102 | * 103 | * @param path The path to use for this read-only cache path 104 | */ 105 | - (void)addReadOnlyCachePath:(NSString *)path; 106 | 107 | /** 108 | * Store an image into memory and disk cache at the given key. 109 | * 110 | * @param image The image to store 111 | * @param key The unique image cache key, usually it's image absolute URL 112 | */ 113 | - (void)storeImage:(UIImage *)image forKey:(NSString *)key; 114 | 115 | /** 116 | * Store an image into memory and optionally disk cache at the given key. 117 | * 118 | * @param image The image to store 119 | * @param key The unique image cache key, usually it's image absolute URL 120 | * @param toDisk Store the image to disk cache if YES 121 | */ 122 | - (void)storeImage:(UIImage *)image forKey:(NSString *)key toDisk:(BOOL)toDisk; 123 | 124 | /** 125 | * Store an image into memory and optionally disk cache at the given key. 126 | * 127 | * @param image The image to store 128 | * @param recalculate BOOL indicates if imageData can be used or a new data should be constructed from the UIImage 129 | * @param imageData The image data as returned by the server, this representation will be used for disk storage 130 | * instead of converting the given image object into a storable/compressed image format in order 131 | * to save quality and CPU 132 | * @param key The unique image cache key, usually it's image absolute URL 133 | * @param toDisk Store the image to disk cache if YES 134 | */ 135 | - (void)storeImage:(UIImage *)image recalculateFromImage:(BOOL)recalculate imageData:(NSData *)imageData forKey:(NSString *)key toDisk:(BOOL)toDisk; 136 | 137 | /** 138 | * Query the disk cache asynchronously. 139 | * 140 | * @param key The unique key used to store the wanted image 141 | */ 142 | - (NSOperation *)queryDiskCacheForKey:(NSString *)key done:(SDWebImageQueryCompletedBlock)doneBlock; 143 | 144 | /** 145 | * Query the memory cache synchronously. 146 | * 147 | * @param key The unique key used to store the wanted image 148 | */ 149 | - (UIImage *)imageFromMemoryCacheForKey:(NSString *)key; 150 | 151 | /** 152 | * Query the disk cache synchronously after checking the memory cache. 153 | * 154 | * @param key The unique key used to store the wanted image 155 | */ 156 | - (UIImage *)imageFromDiskCacheForKey:(NSString *)key; 157 | 158 | /** 159 | * Remove the image from memory and disk cache synchronously 160 | * 161 | * @param key The unique image cache key 162 | */ 163 | - (void)removeImageForKey:(NSString *)key; 164 | 165 | 166 | /** 167 | * Remove the image from memory and disk cache asynchronously 168 | * 169 | * @param key The unique image cache key 170 | * @param completion An block that should be executed after the image has been removed (optional) 171 | */ 172 | - (void)removeImageForKey:(NSString *)key withCompletion:(SDWebImageNoParamsBlock)completion; 173 | 174 | /** 175 | * Remove the image from memory and optionally disk cache asynchronously 176 | * 177 | * @param key The unique image cache key 178 | * @param fromDisk Also remove cache entry from disk if YES 179 | */ 180 | - (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk; 181 | 182 | /** 183 | * Remove the image from memory and optionally disk cache asynchronously 184 | * 185 | * @param key The unique image cache key 186 | * @param fromDisk Also remove cache entry from disk if YES 187 | * @param completion An block that should be executed after the image has been removed (optional) 188 | */ 189 | - (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk withCompletion:(SDWebImageNoParamsBlock)completion; 190 | 191 | /** 192 | * Clear all memory cached images 193 | */ 194 | - (void)clearMemory; 195 | 196 | /** 197 | * Clear all disk cached images. Non-blocking method - returns immediately. 198 | * @param completion An block that should be executed after cache expiration completes (optional) 199 | */ 200 | - (void)clearDiskOnCompletion:(SDWebImageNoParamsBlock)completion; 201 | 202 | /** 203 | * Clear all disk cached images 204 | * @see clearDiskOnCompletion: 205 | */ 206 | - (void)clearDisk; 207 | 208 | /** 209 | * Remove all expired cached image from disk. Non-blocking method - returns immediately. 210 | * @param completionBlock An block that should be executed after cache expiration completes (optional) 211 | */ 212 | - (void)cleanDiskWithCompletionBlock:(SDWebImageNoParamsBlock)completionBlock; 213 | 214 | /** 215 | * Remove all expired cached image from disk 216 | * @see cleanDiskWithCompletionBlock: 217 | */ 218 | - (void)cleanDisk; 219 | 220 | /** 221 | * Get the size used by the disk cache 222 | */ 223 | - (NSUInteger)getSize; 224 | 225 | /** 226 | * Get the number of images in the disk cache 227 | */ 228 | - (NSUInteger)getDiskCount; 229 | 230 | /** 231 | * Asynchronously calculate the disk cache's size. 232 | */ 233 | - (void)calculateSizeWithCompletionBlock:(SDWebImageCalculateSizeBlock)completionBlock; 234 | 235 | /** 236 | * Async check if image exists in disk cache already (does not load the image) 237 | * 238 | * @param key the key describing the url 239 | * @param completionBlock the block to be executed when the check is done. 240 | * @note the completion block will be always executed on the main queue 241 | */ 242 | - (void)diskImageExistsWithKey:(NSString *)key completion:(SDWebImageCheckCacheCompletionBlock)completionBlock; 243 | 244 | /** 245 | * Check if image exists in disk cache already (does not load the image) 246 | * 247 | * @param key the key describing the url 248 | * 249 | * @return YES if an image exists for the given key 250 | */ 251 | - (BOOL)diskImageExistsWithKey:(NSString *)key; 252 | 253 | /** 254 | * Get the cache path for a certain key (needs the cache path root folder) 255 | * 256 | * @param key the key (can be obtained from url using cacheKeyForURL) 257 | * @param path the cache path root folder 258 | * 259 | * @return the cache path 260 | */ 261 | - (NSString *)cachePathForKey:(NSString *)key inPath:(NSString *)path; 262 | 263 | /** 264 | * Get the default cache path for a certain key 265 | * 266 | * @param key the key (can be obtained from url using cacheKeyForURL) 267 | * 268 | * @return the default cache path 269 | */ 270 | - (NSString *)defaultCachePathForKey:(NSString *)key; 271 | 272 | @end 273 | -------------------------------------------------------------------------------- /SDWebImage/UIImageView+WebCache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import "SDWebImageCompat.h" 10 | #import "SDWebImageManager.h" 11 | 12 | /** 13 | * Integrates SDWebImage async downloading and caching of remote images with UIImageView. 14 | * 15 | * Usage with a UITableViewCell sub-class: 16 | * 17 | * @code 18 | 19 | #import 20 | 21 | ... 22 | 23 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 24 | { 25 | static NSString *MyIdentifier = @"MyIdentifier"; 26 | 27 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 28 | 29 | if (cell == nil) { 30 | cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] 31 | autorelease]; 32 | } 33 | 34 | // Here we use the provided sd_setImageWithURL: method to load the web image 35 | // Ensure you use a placeholder image otherwise cells will be initialized with no image 36 | [cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://example.com/image.jpg"] 37 | placeholderImage:[UIImage imageNamed:@"placeholder"]]; 38 | 39 | cell.textLabel.text = @"My Text"; 40 | return cell; 41 | } 42 | 43 | * @endcode 44 | */ 45 | @interface UIImageView (WebCache) 46 | 47 | /** 48 | * Get the current image URL. 49 | * 50 | * Note that because of the limitations of categories this property can get out of sync 51 | * if you use sd_setImage: directly. 52 | */ 53 | - (NSURL *)sd_imageURL; 54 | 55 | /** 56 | * Set the imageView `image` with an `url`. 57 | * 58 | * The download is asynchronous and cached. 59 | * 60 | * @param url The url for the image. 61 | */ 62 | - (void)sd_setImageWithURL:(NSURL *)url; 63 | 64 | /** 65 | * Set the imageView `image` with an `url` and a placeholder. 66 | * 67 | * The download is asynchronous and cached. 68 | * 69 | * @param url The url for the image. 70 | * @param placeholder The image to be set initially, until the image request finishes. 71 | * @see sd_setImageWithURL:placeholderImage:options: 72 | */ 73 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder; 74 | 75 | /** 76 | * Set the imageView `image` with an `url`, placeholder and custom options. 77 | * 78 | * The download is asynchronous and cached. 79 | * 80 | * @param url The url for the image. 81 | * @param placeholder The image to be set initially, until the image request finishes. 82 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. 83 | */ 84 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; 85 | 86 | /** 87 | * Set the imageView `image` with an `url`. 88 | * 89 | * The download is asynchronous and cached. 90 | * 91 | * @param url The url for the image. 92 | * @param completedBlock A block called when operation has been completed. This block has no return value 93 | * and takes the requested UIImage as first parameter. In case of error the image parameter 94 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 95 | * indicating if the image was retrieved from the local cache or from the network. 96 | * The fourth parameter is the original image url. 97 | */ 98 | - (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock; 99 | 100 | /** 101 | * Set the imageView `image` with an `url`, placeholder. 102 | * 103 | * The download is asynchronous and cached. 104 | * 105 | * @param url The url for the image. 106 | * @param placeholder The image to be set initially, until the image request finishes. 107 | * @param completedBlock A block called when operation has been completed. This block has no return value 108 | * and takes the requested UIImage as first parameter. In case of error the image parameter 109 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 110 | * indicating if the image was retrieved from the local cache or from the network. 111 | * The fourth parameter is the original image url. 112 | */ 113 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; 114 | 115 | /** 116 | * Set the imageView `image` with an `url`, placeholder and custom options. 117 | * 118 | * The download is asynchronous and cached. 119 | * 120 | * @param url The url for the image. 121 | * @param placeholder The image to be set initially, until the image request finishes. 122 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. 123 | * @param completedBlock A block called when operation has been completed. This block has no return value 124 | * and takes the requested UIImage as first parameter. In case of error the image parameter 125 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 126 | * indicating if the image was retrieved from the local cache or from the network. 127 | * The fourth parameter is the original image url. 128 | */ 129 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; 130 | 131 | /** 132 | * Set the imageView `image` with an `url`, placeholder and custom options. 133 | * 134 | * The download is asynchronous and cached. 135 | * 136 | * @param url The url for the image. 137 | * @param placeholder The image to be set initially, until the image request finishes. 138 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. 139 | * @param progressBlock A block called while image is downloading 140 | * @param completedBlock A block called when operation has been completed. This block has no return value 141 | * and takes the requested UIImage as first parameter. In case of error the image parameter 142 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 143 | * indicating if the image was retrieved from the local cache or from the network. 144 | * The fourth parameter is the original image url. 145 | */ 146 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock; 147 | 148 | /** 149 | * Set the imageView `image` with an `url` and optionally a placeholder image. 150 | * 151 | * The download is asynchronous and cached. 152 | * 153 | * @param url The url for the image. 154 | * @param placeholder The image to be set initially, until the image request finishes. 155 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. 156 | * @param progressBlock A block called while image is downloading 157 | * @param completedBlock A block called when operation has been completed. This block has no return value 158 | * and takes the requested UIImage as first parameter. In case of error the image parameter 159 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 160 | * indicating if the image was retrieved from the local cache or from the network. 161 | * The fourth parameter is the original image url. 162 | */ 163 | - (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock; 164 | 165 | /** 166 | * Download an array of images and starts them in an animation loop 167 | * 168 | * @param arrayOfURLs An array of NSURL 169 | */ 170 | - (void)sd_setAnimationImagesWithURLs:(NSArray *)arrayOfURLs; 171 | 172 | /** 173 | * Cancel the current download 174 | */ 175 | - (void)sd_cancelCurrentImageLoad; 176 | 177 | - (void)sd_cancelCurrentAnimationImagesLoad; 178 | 179 | /** 180 | * Show activity UIActivityIndicatorView 181 | */ 182 | - (void)setShowActivityIndicatorView:(BOOL)show; 183 | 184 | /** 185 | * set desired UIActivityIndicatorViewStyle 186 | * 187 | * @param style The style of the UIActivityIndicatorView 188 | */ 189 | - (void)setIndicatorStyle:(UIActivityIndicatorViewStyle)style; 190 | 191 | @end 192 | 193 | 194 | @interface UIImageView (WebCacheDeprecated) 195 | 196 | - (NSURL *)imageURL __deprecated_msg("Use `sd_imageURL`"); 197 | 198 | - (void)setImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:`"); 199 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:`"); 200 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options`"); 201 | 202 | - (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:completed:`"); 203 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:completed:`"); 204 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:completed:`"); 205 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:progress:completed:`"); 206 | 207 | - (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs __deprecated_msg("Use `sd_setAnimationImagesWithURLs:`"); 208 | 209 | - (void)cancelCurrentArrayLoad __deprecated_msg("Use `sd_cancelCurrentAnimationImagesLoad`"); 210 | 211 | - (void)cancelCurrentImageLoad __deprecated_msg("Use `sd_cancelCurrentImageLoad`"); 212 | 213 | @end 214 | -------------------------------------------------------------------------------- /SDWebImage/SDWebImageManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import "SDWebImageCompat.h" 10 | #import "SDWebImageOperation.h" 11 | #import "SDWebImageDownloader.h" 12 | #import "SDImageCache.h" 13 | 14 | typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) { 15 | /** 16 | * By default, when a URL fail to be downloaded, the URL is blacklisted so the library won't keep trying. 17 | * This flag disable this blacklisting. 18 | */ 19 | SDWebImageRetryFailed = 1 << 0, 20 | 21 | /** 22 | * By default, image downloads are started during UI interactions, this flags disable this feature, 23 | * leading to delayed download on UIScrollView deceleration for instance. 24 | */ 25 | SDWebImageLowPriority = 1 << 1, 26 | 27 | /** 28 | * This flag disables on-disk caching 29 | */ 30 | SDWebImageCacheMemoryOnly = 1 << 2, 31 | 32 | /** 33 | * This flag enables progressive download, the image is displayed progressively during download as a browser would do. 34 | * By default, the image is only displayed once completely downloaded. 35 | */ 36 | SDWebImageProgressiveDownload = 1 << 3, 37 | 38 | /** 39 | * Even if the image is cached, respect the HTTP response cache control, and refresh the image from remote location if needed. 40 | * The disk caching will be handled by NSURLCache instead of SDWebImage leading to slight performance degradation. 41 | * This option helps deal with images changing behind the same request URL, e.g. Facebook graph api profile pics. 42 | * If a cached image is refreshed, the completion block is called once with the cached image and again with the final image. 43 | * 44 | * Use this flag only if you can't make your URLs static with embedded cache busting parameter. 45 | */ 46 | SDWebImageRefreshCached = 1 << 4, 47 | 48 | /** 49 | * In iOS 4+, continue the download of the image if the app goes to background. This is achieved by asking the system for 50 | * extra time in background to let the request finish. If the background task expires the operation will be cancelled. 51 | */ 52 | SDWebImageContinueInBackground = 1 << 5, 53 | 54 | /** 55 | * Handles cookies stored in NSHTTPCookieStore by setting 56 | * NSMutableURLRequest.HTTPShouldHandleCookies = YES; 57 | */ 58 | SDWebImageHandleCookies = 1 << 6, 59 | 60 | /** 61 | * Enable to allow untrusted SSL certificates. 62 | * Useful for testing purposes. Use with caution in production. 63 | */ 64 | SDWebImageAllowInvalidSSLCertificates = 1 << 7, 65 | 66 | /** 67 | * By default, image are loaded in the order they were queued. This flag move them to 68 | * the front of the queue and is loaded immediately instead of waiting for the current queue to be loaded (which 69 | * could take a while). 70 | */ 71 | SDWebImageHighPriority = 1 << 8, 72 | 73 | /** 74 | * By default, placeholder images are loaded while the image is loading. This flag will delay the loading 75 | * of the placeholder image until after the image has finished loading. 76 | */ 77 | SDWebImageDelayPlaceholder = 1 << 9, 78 | 79 | /** 80 | * We usually don't call transformDownloadedImage delegate method on animated images, 81 | * as most transformation code would mangle it. 82 | * Use this flag to transform them anyway. 83 | */ 84 | SDWebImageTransformAnimatedImage = 1 << 10, 85 | 86 | /** 87 | * By default, image is added to the imageView after download. But in some cases, we want to 88 | * have the hand before setting the image (apply a filter or add it with cross-fade animation for instance) 89 | * Use this flag if you want to manually set the image in the completion when success 90 | */ 91 | SDWebImageAvoidAutoSetImage = 1 << 11 92 | }; 93 | 94 | typedef void(^SDWebImageCompletionBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL); 95 | 96 | typedef void(^SDWebImageCompletionWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL); 97 | 98 | typedef NSString *(^SDWebImageCacheKeyFilterBlock)(NSURL *url); 99 | 100 | 101 | @class SDWebImageManager; 102 | 103 | @protocol SDWebImageManagerDelegate 104 | 105 | @optional 106 | 107 | /** 108 | * Controls which image should be downloaded when the image is not found in the cache. 109 | * 110 | * @param imageManager The current `SDWebImageManager` 111 | * @param imageURL The url of the image to be downloaded 112 | * 113 | * @return Return NO to prevent the downloading of the image on cache misses. If not implemented, YES is implied. 114 | */ 115 | - (BOOL)imageManager:(SDWebImageManager *)imageManager shouldDownloadImageForURL:(NSURL *)imageURL; 116 | 117 | /** 118 | * Allows to transform the image immediately after it has been downloaded and just before to cache it on disk and memory. 119 | * NOTE: This method is called from a global queue in order to not to block the main thread. 120 | * 121 | * @param imageManager The current `SDWebImageManager` 122 | * @param image The image to transform 123 | * @param imageURL The url of the image to transform 124 | * 125 | * @return The transformed image object. 126 | */ 127 | - (UIImage *)imageManager:(SDWebImageManager *)imageManager transformDownloadedImage:(UIImage *)image withURL:(NSURL *)imageURL; 128 | 129 | @end 130 | 131 | /** 132 | * The SDWebImageManager is the class behind the UIImageView+WebCache category and likes. 133 | * It ties the asynchronous downloader (SDWebImageDownloader) with the image cache store (SDImageCache). 134 | * You can use this class directly to benefit from web image downloading with caching in another context than 135 | * a UIView. 136 | * 137 | * Here is a simple example of how to use SDWebImageManager: 138 | * 139 | * @code 140 | 141 | SDWebImageManager *manager = [SDWebImageManager sharedManager]; 142 | [manager downloadImageWithURL:imageURL 143 | options:0 144 | progress:nil 145 | completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { 146 | if (image) { 147 | // do something with image 148 | } 149 | }]; 150 | 151 | * @endcode 152 | */ 153 | @interface SDWebImageManager : NSObject 154 | 155 | @property (weak, nonatomic) id delegate; 156 | 157 | @property (strong, nonatomic, readonly) SDImageCache *imageCache; 158 | @property (strong, nonatomic, readonly) SDWebImageDownloader *imageDownloader; 159 | 160 | /** 161 | * The cache filter is a block used each time SDWebImageManager need to convert an URL into a cache key. This can 162 | * be used to remove dynamic part of an image URL. 163 | * 164 | * The following example sets a filter in the application delegate that will remove any query-string from the 165 | * URL before to use it as a cache key: 166 | * 167 | * @code 168 | 169 | [[SDWebImageManager sharedManager] setCacheKeyFilter:^(NSURL *url) { 170 | url = [[NSURL alloc] initWithScheme:url.scheme host:url.host path:url.path]; 171 | return [url absoluteString]; 172 | }]; 173 | 174 | * @endcode 175 | */ 176 | @property (nonatomic, copy) SDWebImageCacheKeyFilterBlock cacheKeyFilter; 177 | 178 | /** 179 | * Returns global SDWebImageManager instance. 180 | * 181 | * @return SDWebImageManager shared instance 182 | */ 183 | + (SDWebImageManager *)sharedManager; 184 | 185 | /** 186 | * Downloads the image at the given URL if not present in cache or return the cached version otherwise. 187 | * 188 | * @param url The URL to the image 189 | * @param options A mask to specify options to use for this request 190 | * @param progressBlock A block called while image is downloading 191 | * @param completedBlock A block called when operation has been completed. 192 | * 193 | * This parameter is required. 194 | * 195 | * This block has no return value and takes the requested UIImage as first parameter. 196 | * In case of error the image parameter is nil and the second parameter may contain an NSError. 197 | * 198 | * The third parameter is an `SDImageCacheType` enum indicating if the image was retrieved from the local cache 199 | * or from the memory cache or from the network. 200 | * 201 | * The last parameter is set to NO when the SDWebImageProgressiveDownload option is used and the image is 202 | * downloading. This block is thus called repeatedly with a partial image. When image is fully downloaded, the 203 | * block is called a last time with the full image and the last parameter set to YES. 204 | * 205 | * @return Returns an NSObject conforming to SDWebImageOperation. Should be an instance of SDWebImageDownloaderOperation 206 | */ 207 | - (id )downloadImageWithURL:(NSURL *)url 208 | options:(SDWebImageOptions)options 209 | progress:(SDWebImageDownloaderProgressBlock)progressBlock 210 | completed:(SDWebImageCompletionWithFinishedBlock)completedBlock; 211 | 212 | /** 213 | * Saves image to cache for given URL 214 | * 215 | * @param image The image to cache 216 | * @param url The URL to the image 217 | * 218 | */ 219 | 220 | - (void)saveImageToCache:(UIImage *)image forURL:(NSURL *)url; 221 | 222 | /** 223 | * Cancel all current operations 224 | */ 225 | - (void)cancelAll; 226 | 227 | /** 228 | * Check one or more operations running 229 | */ 230 | - (BOOL)isRunning; 231 | 232 | /** 233 | * Check if image has already been cached 234 | * 235 | * @param url image url 236 | * 237 | * @return if the image was already cached 238 | */ 239 | - (BOOL)cachedImageExistsForURL:(NSURL *)url; 240 | 241 | /** 242 | * Check if image has already been cached on disk only 243 | * 244 | * @param url image url 245 | * 246 | * @return if the image was already cached (disk only) 247 | */ 248 | - (BOOL)diskImageExistsForURL:(NSURL *)url; 249 | 250 | /** 251 | * Async check if image has already been cached 252 | * 253 | * @param url image url 254 | * @param completionBlock the block to be executed when the check is finished 255 | * 256 | * @note the completion block is always executed on the main queue 257 | */ 258 | - (void)cachedImageExistsForURL:(NSURL *)url 259 | completion:(SDWebImageCheckCacheCompletionBlock)completionBlock; 260 | 261 | /** 262 | * Async check if image has already been cached on disk only 263 | * 264 | * @param url image url 265 | * @param completionBlock the block to be executed when the check is finished 266 | * 267 | * @note the completion block is always executed on the main queue 268 | */ 269 | - (void)diskImageExistsForURL:(NSURL *)url 270 | completion:(SDWebImageCheckCacheCompletionBlock)completionBlock; 271 | 272 | 273 | /** 274 | *Return the cache key for a given URL 275 | */ 276 | - (NSString *)cacheKeyForURL:(NSURL *)url; 277 | 278 | @end 279 | 280 | 281 | #pragma mark - Deprecated 282 | 283 | typedef void(^SDWebImageCompletedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType) __deprecated_msg("Block type deprecated. Use `SDWebImageCompletionBlock`"); 284 | typedef void(^SDWebImageCompletedWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) __deprecated_msg("Block type deprecated. Use `SDWebImageCompletionWithFinishedBlock`"); 285 | 286 | 287 | @interface SDWebImageManager (Deprecated) 288 | 289 | /** 290 | * Downloads the image at the given URL if not present in cache or return the cached version otherwise. 291 | * 292 | * @deprecated This method has been deprecated. Use `downloadImageWithURL:options:progress:completed:` 293 | */ 294 | - (id )downloadWithURL:(NSURL *)url 295 | options:(SDWebImageOptions)options 296 | progress:(SDWebImageDownloaderProgressBlock)progressBlock 297 | completed:(SDWebImageCompletedWithFinishedBlock)completedBlock __deprecated_msg("Method deprecated. Use `downloadImageWithURL:options:progress:completed:`"); 298 | 299 | @end 300 | -------------------------------------------------------------------------------- /SDWebImage/SDWebImageDownloader.m: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import "SDWebImageDownloader.h" 10 | #import "SDWebImageDownloaderOperation.h" 11 | #import 12 | 13 | static NSString *const kProgressCallbackKey = @"progress"; 14 | static NSString *const kCompletedCallbackKey = @"completed"; 15 | 16 | @interface SDWebImageDownloader () 17 | 18 | @property (strong, nonatomic) NSOperationQueue *downloadQueue; 19 | @property (weak, nonatomic) NSOperation *lastAddedOperation; 20 | @property (assign, nonatomic) Class operationClass; 21 | @property (strong, nonatomic) NSMutableDictionary *URLCallbacks; 22 | @property (strong, nonatomic) NSMutableDictionary *HTTPHeaders; 23 | // This queue is used to serialize the handling of the network responses of all the download operation in a single queue 24 | @property (SDDispatchQueueSetterSementics, nonatomic) dispatch_queue_t barrierQueue; 25 | 26 | @end 27 | 28 | @implementation SDWebImageDownloader 29 | 30 | + (void)initialize { 31 | // Bind SDNetworkActivityIndicator if available (download it here: http://github.com/rs/SDNetworkActivityIndicator ) 32 | // To use it, just add #import "SDNetworkActivityIndicator.h" in addition to the SDWebImage import 33 | if (NSClassFromString(@"SDNetworkActivityIndicator")) { 34 | 35 | #pragma clang diagnostic push 36 | #pragma clang diagnostic ignored "-Warc-performSelector-leaks" 37 | id activityIndicator = [NSClassFromString(@"SDNetworkActivityIndicator") performSelector:NSSelectorFromString(@"sharedActivityIndicator")]; 38 | #pragma clang diagnostic pop 39 | 40 | // Remove observer in case it was previously added. 41 | [[NSNotificationCenter defaultCenter] removeObserver:activityIndicator name:SDWebImageDownloadStartNotification object:nil]; 42 | [[NSNotificationCenter defaultCenter] removeObserver:activityIndicator name:SDWebImageDownloadStopNotification object:nil]; 43 | 44 | [[NSNotificationCenter defaultCenter] addObserver:activityIndicator 45 | selector:NSSelectorFromString(@"startActivity") 46 | name:SDWebImageDownloadStartNotification object:nil]; 47 | [[NSNotificationCenter defaultCenter] addObserver:activityIndicator 48 | selector:NSSelectorFromString(@"stopActivity") 49 | name:SDWebImageDownloadStopNotification object:nil]; 50 | } 51 | } 52 | 53 | + (SDWebImageDownloader *)sharedDownloader { 54 | static dispatch_once_t once; 55 | static id instance; 56 | dispatch_once(&once, ^{ 57 | instance = [self new]; 58 | }); 59 | return instance; 60 | } 61 | 62 | - (id)init { 63 | if ((self = [super init])) { 64 | _operationClass = [SDWebImageDownloaderOperation class]; 65 | _shouldDecompressImages = YES; 66 | _executionOrder = SDWebImageDownloaderFIFOExecutionOrder; 67 | _downloadQueue = [NSOperationQueue new]; 68 | _downloadQueue.maxConcurrentOperationCount = 6; 69 | _URLCallbacks = [NSMutableDictionary new]; 70 | #ifdef SD_WEBP 71 | _HTTPHeaders = [@{@"Accept": @"image/webp,image/*;q=0.8"} mutableCopy]; 72 | #else 73 | _HTTPHeaders = [@{@"Accept": @"image/*;q=0.8"} mutableCopy]; 74 | #endif 75 | _barrierQueue = dispatch_queue_create("com.hackemist.SDWebImageDownloaderBarrierQueue", DISPATCH_QUEUE_CONCURRENT); 76 | _downloadTimeout = 15.0; 77 | } 78 | return self; 79 | } 80 | 81 | - (void)dealloc { 82 | [self.downloadQueue cancelAllOperations]; 83 | SDDispatchQueueRelease(_barrierQueue); 84 | } 85 | 86 | - (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field { 87 | if (value) { 88 | self.HTTPHeaders[field] = value; 89 | } 90 | else { 91 | [self.HTTPHeaders removeObjectForKey:field]; 92 | } 93 | } 94 | 95 | - (NSString *)valueForHTTPHeaderField:(NSString *)field { 96 | return self.HTTPHeaders[field]; 97 | } 98 | 99 | - (void)setMaxConcurrentDownloads:(NSInteger)maxConcurrentDownloads { 100 | _downloadQueue.maxConcurrentOperationCount = maxConcurrentDownloads; 101 | } 102 | 103 | - (NSUInteger)currentDownloadCount { 104 | return _downloadQueue.operationCount; 105 | } 106 | 107 | - (NSInteger)maxConcurrentDownloads { 108 | return _downloadQueue.maxConcurrentOperationCount; 109 | } 110 | 111 | - (void)setOperationClass:(Class)operationClass { 112 | _operationClass = operationClass ?: [SDWebImageDownloaderOperation class]; 113 | } 114 | 115 | - (id )downloadImageWithURL:(NSURL *)url options:(SDWebImageDownloaderOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageDownloaderCompletedBlock)completedBlock { 116 | __block SDWebImageDownloaderOperation *operation; 117 | __weak __typeof(self)wself = self; 118 | 119 | [self addProgressCallback:progressBlock completedBlock:completedBlock forURL:url createCallback:^{ 120 | NSTimeInterval timeoutInterval = wself.downloadTimeout; 121 | if (timeoutInterval == 0.0) { 122 | timeoutInterval = 15.0; 123 | } 124 | 125 | // In order to prevent from potential duplicate caching (NSURLCache + SDImageCache) we disable the cache for image requests if told otherwise 126 | NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:(options & SDWebImageDownloaderUseNSURLCache ? NSURLRequestUseProtocolCachePolicy : NSURLRequestReloadIgnoringLocalCacheData) timeoutInterval:timeoutInterval]; 127 | request.HTTPShouldHandleCookies = (options & SDWebImageDownloaderHandleCookies); 128 | request.HTTPShouldUsePipelining = YES; 129 | if (wself.headersFilter) { 130 | request.allHTTPHeaderFields = wself.headersFilter(url, [wself.HTTPHeaders copy]); 131 | } 132 | else { 133 | request.allHTTPHeaderFields = wself.HTTPHeaders; 134 | } 135 | operation = [[wself.operationClass alloc] initWithRequest:request 136 | options:options 137 | progress:^(NSInteger receivedSize, NSInteger expectedSize) { 138 | SDWebImageDownloader *sself = wself; 139 | if (!sself) return; 140 | __block NSArray *callbacksForURL; 141 | dispatch_sync(sself.barrierQueue, ^{ 142 | callbacksForURL = [sself.URLCallbacks[url] copy]; 143 | }); 144 | for (NSDictionary *callbacks in callbacksForURL) { 145 | dispatch_async(dispatch_get_main_queue(), ^{ 146 | SDWebImageDownloaderProgressBlock callback = callbacks[kProgressCallbackKey]; 147 | if (callback) callback(receivedSize, expectedSize); 148 | }); 149 | } 150 | } 151 | completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) { 152 | SDWebImageDownloader *sself = wself; 153 | if (!sself) return; 154 | __block NSArray *callbacksForURL; 155 | dispatch_barrier_sync(sself.barrierQueue, ^{ 156 | callbacksForURL = [sself.URLCallbacks[url] copy]; 157 | if (finished) { 158 | [sself.URLCallbacks removeObjectForKey:url]; 159 | } 160 | }); 161 | for (NSDictionary *callbacks in callbacksForURL) { 162 | SDWebImageDownloaderCompletedBlock callback = callbacks[kCompletedCallbackKey]; 163 | if (callback) callback(image, data, error, finished); 164 | } 165 | } 166 | cancelled:^{ 167 | SDWebImageDownloader *sself = wself; 168 | if (!sself) return; 169 | dispatch_barrier_async(sself.barrierQueue, ^{ 170 | [sself.URLCallbacks removeObjectForKey:url]; 171 | }); 172 | }]; 173 | operation.shouldDecompressImages = wself.shouldDecompressImages; 174 | 175 | if (wself.urlCredential) { 176 | operation.credential = wself.urlCredential; 177 | } else if (wself.username && wself.password) { 178 | operation.credential = [NSURLCredential credentialWithUser:wself.username password:wself.password persistence:NSURLCredentialPersistenceForSession]; 179 | } 180 | 181 | if (options & SDWebImageDownloaderHighPriority) { 182 | operation.queuePriority = NSOperationQueuePriorityHigh; 183 | } else if (options & SDWebImageDownloaderLowPriority) { 184 | operation.queuePriority = NSOperationQueuePriorityLow; 185 | } 186 | 187 | [wself.downloadQueue addOperation:operation]; 188 | if (wself.executionOrder == SDWebImageDownloaderLIFOExecutionOrder) { 189 | // Emulate LIFO execution order by systematically adding new operations as last operation's dependency 190 | [wself.lastAddedOperation addDependency:operation]; 191 | wself.lastAddedOperation = operation; 192 | } 193 | }]; 194 | 195 | return operation; 196 | } 197 | 198 | - (void)addProgressCallback:(SDWebImageDownloaderProgressBlock)progressBlock completedBlock:(SDWebImageDownloaderCompletedBlock)completedBlock forURL:(NSURL *)url createCallback:(SDWebImageNoParamsBlock)createCallback { 199 | // The URL will be used as the key to the callbacks dictionary so it cannot be nil. If it is nil immediately call the completed block with no image or data. 200 | if (url == nil) { 201 | if (completedBlock != nil) { 202 | completedBlock(nil, nil, nil, NO); 203 | } 204 | return; 205 | } 206 | 207 | dispatch_barrier_sync(self.barrierQueue, ^{ 208 | BOOL first = NO; 209 | if (!self.URLCallbacks[url]) { 210 | self.URLCallbacks[url] = [NSMutableArray new]; 211 | first = YES; 212 | } 213 | 214 | // Handle single download of simultaneous download request for the same URL 215 | NSMutableArray *callbacksForURL = self.URLCallbacks[url]; 216 | NSMutableDictionary *callbacks = [NSMutableDictionary new]; 217 | if (progressBlock) callbacks[kProgressCallbackKey] = [progressBlock copy]; 218 | if (completedBlock) callbacks[kCompletedCallbackKey] = [completedBlock copy]; 219 | [callbacksForURL addObject:callbacks]; 220 | self.URLCallbacks[url] = callbacksForURL; 221 | 222 | if (first) { 223 | createCallback(); 224 | } 225 | }); 226 | } 227 | 228 | - (void)setSuspended:(BOOL)suspended { 229 | [self.downloadQueue setSuspended:suspended]; 230 | } 231 | 232 | @end 233 | --------------------------------------------------------------------------------