├── .gitignore ├── LICENSE ├── MSSBrowse ├── MSSBrowse.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata └── MSSBrowse │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ └── LaunchImage.launchimage │ │ ├── 1242-2208.png │ │ ├── 640-1136.png │ │ ├── 640-960.png │ │ ├── 750-1334.png │ │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Images.xcassets │ └── Contents.json │ ├── Info.plist │ ├── MSSBrowse │ ├── MSSBrowseActionSheet.h │ ├── MSSBrowseActionSheet.m │ ├── MSSBrowseActionSheetCell.h │ ├── MSSBrowseActionSheetCell.m │ ├── MSSBrowseBaseViewController.h │ ├── MSSBrowseBaseViewController.m │ ├── MSSBrowseCollectionViewCell.h │ ├── MSSBrowseCollectionViewCell.m │ ├── MSSBrowseDefine.h │ ├── MSSBrowseLoadingImageView.h │ ├── MSSBrowseLoadingImageView.m │ ├── MSSBrowseLocalViewController.h │ ├── MSSBrowseLocalViewController.m │ ├── MSSBrowseModel.h │ ├── MSSBrowseModel.m │ ├── MSSBrowseNetworkViewController.h │ ├── MSSBrowseNetworkViewController.m │ ├── MSSBrowseRemindView.h │ ├── MSSBrowseRemindView.m │ ├── MSSBrowseZoomScrollView.h │ ├── MSSBrowseZoomScrollView.m │ ├── UIImage+MSSScale.h │ ├── UIImage+MSSScale.m │ ├── UIView+MSSLayout.h │ ├── UIView+MSSLayout.m │ ├── mss_browseLoading@2x.png │ └── mss_browseLoading@3x.png │ ├── MSSCollectionViewCell.h │ ├── MSSCollectionViewCell.m │ ├── SDWebImage │ ├── MKAnnotationView+WebCache.h │ ├── MKAnnotationView+WebCache.m │ ├── NSData+ImageContentType.h │ ├── NSData+ImageContentType.m │ ├── SDImageCache.h │ ├── SDImageCache.m │ ├── SDWebImageCompat.h │ ├── SDWebImageCompat.m │ ├── SDWebImageDecoder.h │ ├── SDWebImageDecoder.m │ ├── SDWebImageDownloader.h │ ├── SDWebImageDownloader.m │ ├── SDWebImageDownloaderOperation.h │ ├── SDWebImageDownloaderOperation.m │ ├── SDWebImageManager.h │ ├── SDWebImageManager.m │ ├── SDWebImageOperation.h │ ├── SDWebImagePrefetcher.h │ ├── SDWebImagePrefetcher.m │ ├── UIButton+WebCache.h │ ├── UIButton+WebCache.m │ ├── UIImage+GIF.h │ ├── UIImage+GIF.m │ ├── UIImage+MultiFormat.h │ ├── UIImage+MultiFormat.m │ ├── UIImage+WebP.h │ ├── UIImage+WebP.m │ ├── UIImageView+HighlightedWebCache.h │ ├── UIImageView+HighlightedWebCache.m │ ├── UIImageView+WebCache.h │ ├── UIImageView+WebCache.m │ ├── UIView+WebCacheOperation.h │ └── UIView+WebCacheOperation.m │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── README.md └── browse.gif /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | #Pods/ 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 JDY0306 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 16/2/27. 6 | // Copyright © 2016年 于威. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 16/2/27. 6 | // Copyright © 2016年 于威. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // 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. 25 | // 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. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // 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. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // 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. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // 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. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "83.5x83.5", 66 | "scale" : "2x" 67 | } 68 | ], 69 | "info" : { 70 | "version" : 1, 71 | "author" : "xcode" 72 | } 73 | } -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/Assets.xcassets/LaunchImage.launchimage/1242-2208.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MSS0306/MSSBrowse/2adc1ef8ea8841848c73a96bbad793a3e150b40d/MSSBrowse/MSSBrowse/Assets.xcassets/LaunchImage.launchimage/1242-2208.png -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/Assets.xcassets/LaunchImage.launchimage/640-1136.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MSS0306/MSSBrowse/2adc1ef8ea8841848c73a96bbad793a3e150b40d/MSSBrowse/MSSBrowse/Assets.xcassets/LaunchImage.launchimage/640-1136.png -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/Assets.xcassets/LaunchImage.launchimage/640-960.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MSS0306/MSSBrowse/2adc1ef8ea8841848c73a96bbad793a3e150b40d/MSSBrowse/MSSBrowse/Assets.xcassets/LaunchImage.launchimage/640-960.png -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/Assets.xcassets/LaunchImage.launchimage/750-1334.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MSS0306/MSSBrowse/2adc1ef8ea8841848c73a96bbad793a3e150b40d/MSSBrowse/MSSBrowse/Assets.xcassets/LaunchImage.launchimage/750-1334.png -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/Assets.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "extent" : "full-screen", 5 | "idiom" : "iphone", 6 | "subtype" : "736h", 7 | "filename" : "1242-2208.png", 8 | "minimum-system-version" : "8.0", 9 | "orientation" : "portrait", 10 | "scale" : "3x" 11 | }, 12 | { 13 | "extent" : "full-screen", 14 | "idiom" : "iphone", 15 | "subtype" : "667h", 16 | "filename" : "750-1334.png", 17 | "minimum-system-version" : "8.0", 18 | "orientation" : "portrait", 19 | "scale" : "2x" 20 | }, 21 | { 22 | "orientation" : "portrait", 23 | "idiom" : "iphone", 24 | "filename" : "640-960.png", 25 | "extent" : "full-screen", 26 | "minimum-system-version" : "7.0", 27 | "scale" : "2x" 28 | }, 29 | { 30 | "extent" : "full-screen", 31 | "idiom" : "iphone", 32 | "subtype" : "retina4", 33 | "filename" : "640-1136.png", 34 | "minimum-system-version" : "7.0", 35 | "orientation" : "portrait", 36 | "scale" : "2x" 37 | } 38 | ], 39 | "info" : { 40 | "version" : 1, 41 | "author" : "xcode" 42 | } 43 | } -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/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 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/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 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/Images.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/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 | NSAppTransportSecurity 26 | 27 | NSAllowsArbitraryLoads 28 | 29 | 30 | UIMainStoryboardFile 31 | Main 32 | UIRequiredDeviceCapabilities 33 | 34 | armv7 35 | 36 | UISupportedInterfaceOrientations 37 | 38 | UIInterfaceOrientationPortrait 39 | 40 | UISupportedInterfaceOrientations~ipad 41 | 42 | UIInterfaceOrientationPortrait 43 | UIInterfaceOrientationPortraitUpsideDown 44 | UIInterfaceOrientationLandscapeLeft 45 | UIInterfaceOrientationLandscapeRight 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/MSSBrowse/MSSBrowseActionSheet.h: -------------------------------------------------------------------------------- 1 | // 2 | // MSSBrowseActionSheet.h 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 16/2/14. 6 | // Copyright © 2016年 于威. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void(^MSSBrowseActionSheetDidSelectedAtIndexBlock)(NSInteger index); 12 | 13 | @interface MSSBrowseActionSheet : UIView 14 | 15 | - (instancetype)initWithTitleArray:(NSArray *)titleArray cancelButtonTitle:(NSString *)cancelTitle didSelectedBlock:(MSSBrowseActionSheetDidSelectedAtIndexBlock)selectedBlock; 16 | - (void)showInView:(UIView *)view; 17 | // transform时更新frame 18 | - (void)updateFrame; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/MSSBrowse/MSSBrowseActionSheet.m: -------------------------------------------------------------------------------- 1 | // 2 | // MSSBrowseActionSheet.m 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 16/2/14. 6 | // Copyright © 2016年 于威. All rights reserved. 7 | // 8 | 9 | #define kBrowseActionSheetSpace 10.0f 10 | #define kBrowseActionSheetCellHeight 44.0f 11 | 12 | #import "MSSBrowseActionSheet.h" 13 | #import "MSSBrowseDefine.h" 14 | #import "MSSBrowseActionSheetCell.h" 15 | 16 | @interface MSSBrowseActionSheet () 17 | 18 | @property (nonatomic,strong)UITableView *tableView; 19 | @property (nonatomic,strong)NSArray *titleArray; 20 | @property (nonatomic,copy)NSString *cancelTitle; 21 | @property (nonatomic,copy)MSSBrowseActionSheetDidSelectedAtIndexBlock selectedBlock; 22 | @property (nonatomic,assign)CGFloat tableViewHeight; 23 | @property (nonatomic,strong)UIView *maskView; 24 | 25 | @end 26 | 27 | @implementation MSSBrowseActionSheet 28 | 29 | - (instancetype)initWithTitleArray:(NSArray *)titleArray cancelButtonTitle:(NSString *)cancelTitle didSelectedBlock:(MSSBrowseActionSheetDidSelectedAtIndexBlock)selectedBlock 30 | { 31 | self = [super initWithFrame:CGRectZero]; 32 | if(self) 33 | { 34 | _titleArray = titleArray; 35 | _cancelTitle = cancelTitle; 36 | _selectedBlock = selectedBlock; 37 | _tableViewHeight = (_titleArray.count + 1) * kBrowseActionSheetCellHeight + kBrowseActionSheetSpace; 38 | [self createBrowseActionSheet]; 39 | } 40 | return self; 41 | } 42 | 43 | - (void)createBrowseActionSheet 44 | { 45 | _maskView = [[UIView alloc]init]; 46 | _maskView.backgroundColor = [UIColor blackColor]; 47 | _maskView.alpha = 0.3; 48 | [self addSubview:_maskView]; 49 | 50 | _tableView = [[UITableView alloc]init]; 51 | _tableView.delegate = self; 52 | _tableView.dataSource = self; 53 | _tableView.separatorColor = [UIColor clearColor]; 54 | _tableView.bounces = NO; 55 | [self addSubview:_tableView]; 56 | } 57 | 58 | - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 59 | { 60 | if(section == 1) 61 | { 62 | return kBrowseActionSheetSpace; 63 | } 64 | return 0; 65 | } 66 | 67 | - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 68 | { 69 | if(section == 1) 70 | { 71 | UIView *view = [[UIView alloc]init]; 72 | view.backgroundColor = [UIColor lightGrayColor]; 73 | return view; 74 | } 75 | return nil; 76 | } 77 | 78 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 79 | { 80 | return 2; 81 | } 82 | 83 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 84 | { 85 | if(section == 0) 86 | { 87 | return _titleArray.count; 88 | } 89 | return 1; 90 | } 91 | 92 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 93 | { 94 | static NSString *cellName = @"cell"; 95 | MSSBrowseActionSheetCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName]; 96 | if(cell == nil) 97 | { 98 | cell = [[MSSBrowseActionSheetCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName]; 99 | } 100 | cell.titleLabel.frame = CGRectMake(0, 0, self.mssWidth, kBrowseActionSheetCellHeight); 101 | cell.bottomLineView.hidden = YES; 102 | if(indexPath.section == 0) 103 | { 104 | cell.titleLabel.text = _titleArray[indexPath.row]; 105 | if(_titleArray.count > indexPath.row + 1) 106 | { 107 | cell.bottomLineView.frame = CGRectMake(0, kBrowseActionSheetCellHeight - 1, self.mssWidth,1); 108 | cell.bottomLineView.hidden = NO; 109 | } 110 | } 111 | else 112 | { 113 | cell.titleLabel.text = _cancelTitle; 114 | } 115 | return cell; 116 | } 117 | 118 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath 119 | { 120 | if(indexPath.section == 0) 121 | { 122 | if(_selectedBlock) 123 | { 124 | _selectedBlock(indexPath.row); 125 | } 126 | } 127 | [self disMissActionSheet]; 128 | } 129 | 130 | - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 131 | { 132 | [self disMissActionSheet]; 133 | } 134 | 135 | - (void)disMissActionSheet 136 | { 137 | [UIView animateWithDuration:0.3 animations:^{ 138 | [_tableView setMssY:self.mssHeight]; 139 | } completion:^(BOOL finished) { 140 | [self removeFromSuperview]; 141 | }]; 142 | } 143 | 144 | - (void)showInView:(UIView *)view 145 | { 146 | [view addSubview:self]; 147 | self.frame = view.bounds; 148 | _maskView.frame = view.bounds; 149 | _tableView.frame = CGRectMake(0, self.mssHeight, self.mssWidth, _tableViewHeight); 150 | [UIView animateWithDuration:0.3 animations:^{ 151 | [_tableView setMssY:self.mssHeight - _tableViewHeight]; 152 | }]; 153 | } 154 | 155 | // transform时更新frame 156 | - (void)updateFrame 157 | { 158 | if(self.superview) 159 | { 160 | self.frame = self.superview.bounds; 161 | _maskView.frame = self.superview.bounds; 162 | _tableView.frame = CGRectMake(0, self.mssHeight - _tableViewHeight, self.mssWidth, _tableViewHeight); 163 | [_tableView reloadData]; 164 | } 165 | } 166 | 167 | @end 168 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/MSSBrowse/MSSBrowseActionSheetCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // MSSBrowseActionSheetCell.h 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 16/2/14. 6 | // Copyright © 2016年 于威. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MSSBrowseActionSheetCell : UITableViewCell 12 | 13 | @property (nonatomic,strong)UILabel *titleLabel; 14 | @property (nonatomic,strong)UIView *bottomLineView; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/MSSBrowse/MSSBrowseActionSheetCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // MSSBrowseActionSheetCell.m 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 16/2/14. 6 | // Copyright © 2016年 于威. All rights reserved. 7 | // 8 | 9 | #import "MSSBrowseActionSheetCell.h" 10 | #import "MSSBrowseDefine.h" 11 | 12 | @implementation MSSBrowseActionSheetCell 13 | 14 | - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 15 | { 16 | self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 17 | if(self) 18 | { 19 | [self createCell]; 20 | } 21 | return self; 22 | } 23 | 24 | - (void)createCell 25 | { 26 | _titleLabel = [[UILabel alloc]init]; 27 | _titleLabel.textAlignment = NSTextAlignmentCenter; 28 | [self.contentView addSubview:_titleLabel]; 29 | 30 | _bottomLineView = [[UIView alloc]init]; 31 | _bottomLineView.backgroundColor = [UIColor colorWithRed:0.7f green:0.7f blue:0.7f alpha:1.0f]; 32 | [self.contentView addSubview:_bottomLineView]; 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/MSSBrowse/MSSBrowseBaseViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // MSSBrowseBaseViewController.h 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 16/4/26. 6 | // Copyright © 2016年 于威. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MSSBrowseCollectionViewCell.h" 11 | #import "MSSBrowseModel.h" 12 | 13 | @interface MSSBrowseBaseViewController : UIViewController 14 | 15 | @property (nonatomic,assign)BOOL isEqualRatio;// 大小图是否等比(默认为等比) 16 | 17 | @property (nonatomic,strong)UICollectionView *collectionView; 18 | @property (nonatomic,assign)BOOL isFirstOpen; 19 | @property (nonatomic,assign)CGFloat screenWidth; 20 | @property (nonatomic,assign)CGFloat screenHeight; 21 | 22 | - (instancetype)initWithBrowseItemArray:(NSArray *)browseItemArray currentIndex:(NSInteger)currentIndex; 23 | - (void)showBrowseViewController; 24 | 25 | // 子类重写此方法 26 | - (void)loadBrowseImageWithBrowseItem:(MSSBrowseModel *)browseItem Cell:(MSSBrowseCollectionViewCell *)cell bigImageRect:(CGRect)bigImageRect; 27 | - (void)showBrowseRemindViewWithText:(NSString *)text; 28 | // 获取指定视图在window中的位置 29 | - (CGRect)getFrameInWindow:(UIView *)view; 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/MSSBrowse/MSSBrowseCollectionViewCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // MSSBrowseCollectionViewCell.h 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 15/12/5. 6 | // Copyright © 2015年 于威. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MSSBrowseLoadingImageView.h" 11 | #import "MSSBrowseZoomScrollView.h" 12 | 13 | @class MSSBrowseCollectionViewCell; 14 | 15 | typedef void(^MSSBrowseCollectionViewCellTapBlock)(MSSBrowseCollectionViewCell *browseCell); 16 | typedef void(^MSSBrowseCollectionViewCellLongPressBlock)(MSSBrowseCollectionViewCell *browseCell); 17 | 18 | @interface MSSBrowseCollectionViewCell : UICollectionViewCell 19 | 20 | @property (nonatomic,strong)MSSBrowseZoomScrollView *zoomScrollView; // 滚动视图 21 | @property (nonatomic,strong)MSSBrowseLoadingImageView *loadingView; // 加载视图 22 | 23 | - (void)tapClick:(MSSBrowseCollectionViewCellTapBlock)tapBlock; 24 | - (void)longPress:(MSSBrowseCollectionViewCellLongPressBlock)longPressBlock; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/MSSBrowse/MSSBrowseCollectionViewCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // MSSBrowseCollectionViewCell.m 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 15/12/5. 6 | // Copyright © 2015年 于威. All rights reserved. 7 | // 8 | 9 | #import "MSSBrowseCollectionViewCell.h" 10 | #import "MSSBrowseDefine.h" 11 | 12 | @interface MSSBrowseCollectionViewCell () 13 | 14 | @property (nonatomic,copy)MSSBrowseCollectionViewCellTapBlock tapBlock; 15 | @property (nonatomic,copy)MSSBrowseCollectionViewCellLongPressBlock longPressBlock; 16 | 17 | @end 18 | 19 | @implementation MSSBrowseCollectionViewCell 20 | 21 | - (id)initWithFrame:(CGRect)frame 22 | { 23 | self = [super initWithFrame:frame]; 24 | if(self) 25 | { 26 | [self createCell]; 27 | } 28 | return self; 29 | } 30 | 31 | - (void)createCell 32 | { 33 | _zoomScrollView = [[MSSBrowseZoomScrollView alloc]init]; 34 | __weak __typeof(self)weakSelf = self; 35 | [_zoomScrollView tapClick:^{ 36 | __strong __typeof(weakSelf)strongSelf = weakSelf; 37 | strongSelf.tapBlock(strongSelf); 38 | }]; 39 | [self.contentView addSubview:_zoomScrollView]; 40 | 41 | _loadingView = [[MSSBrowseLoadingImageView alloc]init]; 42 | [_zoomScrollView addSubview:_loadingView]; 43 | 44 | UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressGesture:)]; 45 | [self.contentView addGestureRecognizer:longPressGesture]; 46 | } 47 | 48 | - (void)tapClick:(MSSBrowseCollectionViewCellTapBlock)tapBlock 49 | { 50 | _tapBlock = tapBlock; 51 | } 52 | 53 | - (void)longPress:(MSSBrowseCollectionViewCellLongPressBlock)longPressBlock 54 | { 55 | _longPressBlock = longPressBlock; 56 | } 57 | 58 | - (void)longPressGesture:(UILongPressGestureRecognizer *)gesture 59 | { 60 | if(_longPressBlock) 61 | { 62 | if(gesture.state == UIGestureRecognizerStateBegan) 63 | { 64 | _longPressBlock(self); 65 | } 66 | } 67 | } 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/MSSBrowse/MSSBrowseDefine.h: -------------------------------------------------------------------------------- 1 | // 2 | // MSSBrowseDefine.h 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 15/12/6. 6 | // Copyright © 2015年 于威. All rights reserved. 7 | // 8 | 9 | #define kBrowseSpace 50.0f 10 | 11 | #define MSS_SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width) 12 | #define MSS_SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height) 13 | 14 | #import "MSSBrowseNetworkViewController.h" 15 | #import "MSSBrowseLocalViewController.h" 16 | #import "MSSBrowseModel.h" 17 | #import "UIView+MSSLayout.h" 18 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/MSSBrowse/MSSBrowseLoadingImageView.h: -------------------------------------------------------------------------------- 1 | // 2 | // MSSBrowseLoadingImageView.h 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 16/4/29. 6 | // Copyright © 2016年 于威. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MSSBrowseLoadingImageView : UIImageView 12 | 13 | - (void)startAnimation; 14 | - (void)stopAnimation; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/MSSBrowse/MSSBrowseLoadingImageView.m: -------------------------------------------------------------------------------- 1 | // 2 | // MSSBrowseLoadingImageView.m 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 16/4/29. 6 | // Copyright © 2016年 于威. All rights reserved. 7 | // 8 | 9 | #import "MSSBrowseLoadingImageView.h" 10 | 11 | @interface MSSBrowseLoadingImageView () 12 | 13 | @property (nonatomic,strong)CABasicAnimation *rotationAnimation; 14 | 15 | @end 16 | 17 | @implementation MSSBrowseLoadingImageView 18 | 19 | - (instancetype)initWithFrame:(CGRect)frame 20 | { 21 | self = [super initWithFrame:frame]; 22 | if(self) 23 | { 24 | [self createImageView]; 25 | } 26 | return self; 27 | } 28 | 29 | - (void)createImageView 30 | { 31 | self.image = [UIImage imageNamed:@"mss_browseLoading"]; 32 | _rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; 33 | _rotationAnimation.toValue = [NSNumber numberWithFloat:(2 * M_PI)]; 34 | _rotationAnimation.duration = 0.6f; 35 | _rotationAnimation.repeatCount = FLT_MAX; 36 | } 37 | 38 | - (void)startAnimation 39 | { 40 | self.hidden = NO; 41 | [self.layer addAnimation:_rotationAnimation 42 | forKey:@"rotateAnimation"]; 43 | } 44 | 45 | - (void)stopAnimation 46 | { 47 | self.hidden = YES; 48 | [self.layer removeAnimationForKey:@"rotateAnimation"]; 49 | } 50 | 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/MSSBrowse/MSSBrowseLocalViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // MSSBrowseLocalViewController.h 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 16/4/26. 6 | // Copyright © 2016年 于威. All rights reserved. 7 | // 8 | 9 | #import "MSSBrowseBaseViewController.h" 10 | 11 | // 加载本地图片 12 | @interface MSSBrowseLocalViewController : MSSBrowseBaseViewController 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/MSSBrowse/MSSBrowseLocalViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // MSSBrowseLocalViewController.m 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 16/4/26. 6 | // Copyright © 2016年 于威. All rights reserved. 7 | // 8 | 9 | #import "MSSBrowseLocalViewController.h" 10 | #import "UIImage+MSSScale.h" 11 | 12 | @implementation MSSBrowseLocalViewController 13 | 14 | - (void)loadBrowseImageWithBrowseItem:(MSSBrowseModel *)browseItem Cell:(MSSBrowseCollectionViewCell *)cell bigImageRect:(CGRect)bigImageRect 15 | { 16 | cell.loadingView.hidden = YES; 17 | UIImageView *imageView = cell.zoomScrollView.zoomImageView; 18 | if(browseItem.bigImageLocalPath) 19 | { 20 | NSData *imageData = [[NSData alloc]initWithContentsOfFile:browseItem.bigImageLocalPath]; 21 | imageView.image = [[UIImage alloc]initWithData:imageData]; 22 | } 23 | else if(browseItem.bigImage) 24 | { 25 | imageView.image = browseItem.bigImage; 26 | } 27 | else if(browseItem.bigImageData) 28 | { 29 | imageView.image = [[UIImage alloc]initWithData:browseItem.bigImageData]; 30 | } 31 | else 32 | { 33 | imageView.image = nil; 34 | } 35 | // 当大图frame为空时,需要大图加载完成后重新计算坐标 36 | CGRect bigRect = [self getBigImageRectIfIsEmptyRect:bigImageRect bigImage:imageView.image]; 37 | // 第一次打开浏览页需要加载动画 38 | if(self.isFirstOpen) 39 | { 40 | self.isFirstOpen = NO; 41 | imageView.frame = [self getFrameInWindow:browseItem.smallImageView]; 42 | [UIView animateWithDuration:0.5 animations:^{ 43 | imageView.frame = bigRect; 44 | }]; 45 | } 46 | else 47 | { 48 | imageView.frame = bigRect; 49 | } 50 | } 51 | 52 | // 当大图frame为空时,需要大图加载完成后重新计算坐标 53 | - (CGRect)getBigImageRectIfIsEmptyRect:(CGRect)rect bigImage:(UIImage *)bigImage 54 | { 55 | if(CGRectIsEmpty(rect)) 56 | { 57 | return [bigImage mss_getBigImageRectSizeWithScreenWidth:self.screenWidth screenHeight:self.screenHeight]; 58 | } 59 | return rect; 60 | } 61 | 62 | @end 63 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/MSSBrowse/MSSBrowseModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // MSSBrowseModel.h 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 15/12/5. 6 | // Copyright © 2015年 于威. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface MSSBrowseModel : NSObject 13 | // 加载网络图片大图url地址 14 | @property (nonatomic,copy)NSString *bigImageUrl; 15 | // 加载本地图片(下面三个属性传一个即可) 16 | @property (nonatomic,copy)NSString *bigImageLocalPath;// 建议使用本地图片路径(减少内存使用) 17 | @property (nonatomic,strong)NSData *bigImageData; 18 | @property (nonatomic,strong)UIImage *bigImage; 19 | // 小图(用来转换坐标用) 20 | @property (nonatomic,strong)UIImageView *smallImageView; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/MSSBrowse/MSSBrowseModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // MSSBrowseModel.m 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 15/12/5. 6 | // Copyright © 2015年 于威. All rights reserved. 7 | // 8 | 9 | #import "MSSBrowseModel.h" 10 | 11 | @implementation MSSBrowseModel 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/MSSBrowse/MSSBrowseNetworkViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // MSSBrowseNetworkViewController.h 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 16/4/26. 6 | // Copyright © 2016年 于威. All rights reserved. 7 | // 8 | 9 | #import "MSSBrowseBaseViewController.h" 10 | 11 | // 加载网络图片 12 | @interface MSSBrowseNetworkViewController : MSSBrowseBaseViewController 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/MSSBrowse/MSSBrowseNetworkViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // MSSBrowseNetworkViewController.m 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 16/4/26. 6 | // Copyright © 2016年 于威. All rights reserved. 7 | // 8 | 9 | #import "MSSBrowseNetworkViewController.h" 10 | #import "SDImageCache.h" 11 | #import "UIImageView+WebCache.h" 12 | #import "UIView+MSSLayout.h" 13 | #import "UIImage+MSSScale.h" 14 | 15 | @implementation MSSBrowseNetworkViewController 16 | 17 | - (void)loadBrowseImageWithBrowseItem:(MSSBrowseModel *)browseItem Cell:(MSSBrowseCollectionViewCell *)cell bigImageRect:(CGRect)bigImageRect 18 | { 19 | // 停止加载 20 | [cell.loadingView stopAnimation]; 21 | // 判断大图是否存在 22 | if([[SDImageCache sharedImageCache]diskImageExistsWithKey:browseItem.bigImageUrl]) 23 | { 24 | // 显示大图 25 | [self showBigImage:cell.zoomScrollView.zoomImageView browseItem:browseItem rect:bigImageRect]; 26 | } 27 | // 如果大图不存在 28 | else 29 | { 30 | self.isFirstOpen = NO; 31 | // 加载大图 32 | [self loadBigImageWithBrowseItem:browseItem cell:cell rect:bigImageRect]; 33 | } 34 | } 35 | 36 | - (void)showBigImage:(UIImageView *)imageView browseItem:(MSSBrowseModel *)browseItem rect:(CGRect)rect 37 | { 38 | // 取消当前请求防止复用问题 39 | [imageView sd_cancelCurrentImageLoad]; 40 | // 如果存在直接显示图片 41 | imageView.image = [[SDImageCache sharedImageCache]imageFromDiskCacheForKey:browseItem.bigImageUrl]; 42 | // 当大图frame为空时,需要大图加载完成后重新计算坐标 43 | CGRect bigRect = [self getBigImageRectIfIsEmptyRect:rect bigImage:imageView.image]; 44 | // 第一次打开浏览页需要加载动画 45 | if(self.isFirstOpen) 46 | { 47 | self.isFirstOpen = NO; 48 | imageView.frame = [self getFrameInWindow:browseItem.smallImageView]; 49 | [UIView animateWithDuration:0.5 animations:^{ 50 | imageView.frame = bigRect; 51 | }]; 52 | } 53 | else 54 | { 55 | imageView.frame = bigRect; 56 | } 57 | } 58 | 59 | // 加载大图 60 | - (void)loadBigImageWithBrowseItem:(MSSBrowseModel *)browseItem cell:(MSSBrowseCollectionViewCell *)cell rect:(CGRect)rect 61 | { 62 | UIImageView *imageView = cell.zoomScrollView.zoomImageView; 63 | // 加载圆圈显示 64 | [cell.loadingView startAnimation]; 65 | // 默认为屏幕中间 66 | [imageView mss_setFrameInSuperViewCenterWithSize:CGSizeMake(browseItem.smallImageView.mssWidth, browseItem.smallImageView.mssHeight)]; 67 | [imageView sd_setImageWithURL:[NSURL URLWithString:browseItem.bigImageUrl] placeholderImage:browseItem.smallImageView.image completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 68 | // 关闭图片浏览view的时候,不需要继续执行小图加载大图动画 69 | if(self.collectionView.userInteractionEnabled) 70 | { 71 | // 停止加载 72 | [cell.loadingView stopAnimation]; 73 | if(error) 74 | { 75 | [self showBrowseRemindViewWithText:@"图片加载失败"]; 76 | } 77 | else 78 | { 79 | // 当大图frame为空时,需要大图加载完成后重新计算坐标 80 | CGRect bigRect = [self getBigImageRectIfIsEmptyRect:rect bigImage:image]; 81 | // 图片加载成功 82 | [UIView animateWithDuration:0.5 animations:^{ 83 | imageView.frame = bigRect; 84 | }]; 85 | } 86 | } 87 | }]; 88 | } 89 | 90 | // 当大图frame为空时,需要大图加载完成后重新计算坐标 91 | - (CGRect)getBigImageRectIfIsEmptyRect:(CGRect)rect bigImage:(UIImage *)bigImage 92 | { 93 | if(CGRectIsEmpty(rect)) 94 | { 95 | return [bigImage mss_getBigImageRectSizeWithScreenWidth:self.screenWidth screenHeight:self.screenHeight]; 96 | } 97 | return rect; 98 | } 99 | 100 | @end 101 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/MSSBrowse/MSSBrowseRemindView.h: -------------------------------------------------------------------------------- 1 | // 2 | // MSSBrowseRemindView.h 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 16/2/14. 6 | // Copyright © 2016年 于威. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MSSBrowseRemindView : UIView 12 | 13 | - (void)showRemindViewWithText:(NSString *)text; 14 | - (void)hideRemindView; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/MSSBrowse/MSSBrowseRemindView.m: -------------------------------------------------------------------------------- 1 | // 2 | // MSSBrowseRemindView.m 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 16/2/14. 6 | // Copyright © 2016年 于威. All rights reserved. 7 | // 8 | 9 | #import "MSSBrowseRemindView.h" 10 | #import "UIView+MSSLayout.h" 11 | 12 | @interface MSSBrowseRemindView () 13 | 14 | @property (nonatomic,strong)UILabel *remindLabel; 15 | @property (nonatomic,strong)UIView *maskView; 16 | 17 | @end 18 | 19 | @implementation MSSBrowseRemindView 20 | 21 | - (instancetype)initWithFrame:(CGRect)frame 22 | { 23 | self = [super initWithFrame:frame]; 24 | if(self) 25 | { 26 | [self createRemindView]; 27 | } 28 | return self; 29 | } 30 | 31 | - (void)createRemindView 32 | { 33 | self.alpha = 0; 34 | 35 | _maskView = [[UIView alloc]init]; 36 | _maskView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; 37 | _maskView.backgroundColor = [UIColor blackColor]; 38 | _maskView.alpha = 0.5f; 39 | _maskView.layer.cornerRadius = 5.0f; 40 | _maskView.layer.masksToBounds = YES; 41 | [self addSubview:_maskView]; 42 | 43 | _remindLabel = [[UILabel alloc]init]; 44 | _remindLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; 45 | _remindLabel.font = [UIFont boldSystemFontOfSize:14.0f]; 46 | _remindLabel.textColor = [UIColor whiteColor]; 47 | [self addSubview:_remindLabel]; 48 | } 49 | 50 | - (void)showRemindViewWithText:(NSString *)text 51 | { 52 | CGRect textRect = [text boundingRectWithSize:CGSizeMake(MAXFLOAT,MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:_remindLabel.font} context:nil]; 53 | CGSize size = textRect.size; 54 | [_maskView mss_setFrameInSuperViewCenterWithSize:CGSizeMake(size.width + 20, size.height + 40)]; 55 | [_remindLabel mss_setFrameInSuperViewCenterWithSize:CGSizeMake(size.width, size.height)]; 56 | _remindLabel.text = text; 57 | self.alpha = 0; 58 | [UIView animateWithDuration:0.3 animations:^{ 59 | self.alpha = 1; 60 | }]; 61 | } 62 | 63 | - (void)hideRemindView 64 | { 65 | self.alpha = 1; 66 | [UIView animateWithDuration:0.3 animations:^{ 67 | self.alpha = 0; 68 | }completion:^(BOOL finished) { 69 | 70 | }]; 71 | } 72 | 73 | @end 74 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/MSSBrowse/MSSBrowseZoomScrollView.h: -------------------------------------------------------------------------------- 1 | // 2 | // MSSBrowseZoomScrollView.h 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 15/12/5. 6 | // Copyright © 2015年 于威. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void(^MSSBrowseZoomScrollViewTapBlock)(void); 12 | 13 | @interface MSSBrowseZoomScrollView : UIScrollView 14 | 15 | @property (nonatomic,strong)UIImageView *zoomImageView; 16 | 17 | - (void)tapClick:(MSSBrowseZoomScrollViewTapBlock)tapBlock; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/MSSBrowse/MSSBrowseZoomScrollView.m: -------------------------------------------------------------------------------- 1 | // 2 | // MSSBrowseZoomScrollView.m 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 15/12/5. 6 | // Copyright © 2015年 于威. All rights reserved. 7 | // 8 | 9 | #import "MSSBrowseZoomScrollView.h" 10 | #import "MSSBrowseDefine.h" 11 | 12 | @interface MSSBrowseZoomScrollView () 13 | 14 | @property (nonatomic,copy)MSSBrowseZoomScrollViewTapBlock tapBlock; 15 | @property (nonatomic,assign)BOOL isSingleTap; 16 | 17 | @end 18 | 19 | @implementation MSSBrowseZoomScrollView 20 | 21 | - (id)initWithFrame:(CGRect)frame 22 | { 23 | self = [super initWithFrame:frame]; 24 | if (self) { 25 | // Initialization code 26 | [self createZoomScrollView]; 27 | } 28 | return self; 29 | } 30 | 31 | - (void)createZoomScrollView 32 | { 33 | self.delegate = self; 34 | _isSingleTap = NO; 35 | self.minimumZoomScale = 1.0f; 36 | self.maximumZoomScale = 3.0f; 37 | 38 | _zoomImageView = [[UIImageView alloc]init]; 39 | _zoomImageView.userInteractionEnabled = YES; 40 | [self addSubview:_zoomImageView]; 41 | } 42 | 43 | - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView 44 | { 45 | return _zoomImageView; 46 | } 47 | 48 | - (void)scrollViewDidZoom:(UIScrollView *)scrollView 49 | { 50 | // 延中心点缩放 51 | CGRect rect = _zoomImageView.frame; 52 | rect.origin.x = 0; 53 | rect.origin.y = 0; 54 | if (rect.size.width < self.mssWidth) { 55 | rect.origin.x = floorf((self.mssWidth - rect.size.width) / 2.0); 56 | } 57 | if (rect.size.height < self.mssHeight) { 58 | rect.origin.y = floorf((self.mssHeight - rect.size.height) / 2.0); 59 | } 60 | _zoomImageView.frame = rect; 61 | } 62 | 63 | - (void)tapClick:(MSSBrowseZoomScrollViewTapBlock)tapBlock 64 | { 65 | _tapBlock = tapBlock; 66 | } 67 | 68 | - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 69 | { 70 | UITouch *touch = touches.anyObject; 71 | if(touch.tapCount == 1) 72 | { 73 | [self performSelector:@selector(singleTapClick) withObject:nil afterDelay:0.17]; 74 | } 75 | else 76 | { 77 | [NSObject cancelPreviousPerformRequestsWithTarget:self]; 78 | // 防止先执行单击手势后还执行下面双击手势动画异常问题 79 | if(!_isSingleTap) 80 | { 81 | CGPoint touchPoint = [touch locationInView:_zoomImageView]; 82 | [self zoomDoubleTapWithPoint:touchPoint]; 83 | } 84 | } 85 | } 86 | 87 | - (void)singleTapClick 88 | { 89 | _isSingleTap = YES; 90 | if(_tapBlock) 91 | { 92 | _tapBlock(); 93 | } 94 | } 95 | 96 | - (void)zoomDoubleTapWithPoint:(CGPoint)touchPoint 97 | { 98 | if(self.zoomScale > self.minimumZoomScale) 99 | { 100 | [self setZoomScale:self.minimumZoomScale animated:YES]; 101 | } 102 | else 103 | { 104 | CGFloat width = self.bounds.size.width / self.maximumZoomScale; 105 | CGFloat height = self.bounds.size.height / self.maximumZoomScale; 106 | [self zoomToRect:CGRectMake(touchPoint.x - width / 2, touchPoint.y - height / 2, width, height) animated:YES]; 107 | } 108 | } 109 | 110 | 111 | @end 112 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/MSSBrowse/UIImage+MSSScale.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+MSSScale.h 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 15/12/6. 6 | // Copyright © 2015年 于威. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIImage (MSSScale) 12 | 13 | // 得到图像显示完整后的frame 14 | - (CGRect)mss_getBigImageRectSizeWithScreenWidth:(CGFloat)screenWidth screenHeight:(CGFloat)screenHeight; 15 | @end 16 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/MSSBrowse/UIImage+MSSScale.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+MSSScale.m 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 15/12/6. 6 | // Copyright © 2015年 于威. All rights reserved. 7 | // 8 | 9 | #import "UIImage+MSSScale.h" 10 | 11 | @implementation UIImage (MSSScale) 12 | 13 | // 得到图像显示完整后的宽度和高度 14 | - (CGRect)mss_getBigImageRectSizeWithScreenWidth:(CGFloat)screenWidth screenHeight:(CGFloat)screenHeight 15 | { 16 | CGFloat widthRatio = screenWidth / self.size.width; 17 | CGFloat heightRatio = screenHeight / self.size.height; 18 | CGFloat scale = MIN(widthRatio, heightRatio); 19 | CGFloat width = scale * self.size.width; 20 | CGFloat height = scale * self.size.height; 21 | return CGRectMake((screenWidth - width) / 2, (screenHeight - height) / 2, width, height); 22 | } 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/MSSBrowse/UIView+MSSLayout.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+MSSLayout.h 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 15/12/5. 6 | // Copyright © 2015年 于威. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIView (MSSLayout) 12 | 13 | - (CGFloat)mssLeft; 14 | - (CGFloat)mssRight; 15 | - (CGFloat)mssBottom; 16 | - (CGFloat)mssTop; 17 | - (CGFloat)mssHeight; 18 | - (CGFloat)mssWidth; 19 | 20 | - (void)setMssX:(CGFloat)mssX; 21 | - (void)setMssY:(CGFloat)mssY; 22 | - (void)setMssWidth:(CGFloat)mssWidth; 23 | - (void)setMssHeight:(CGFloat)mssHeight; 24 | 25 | - (void)mss_setFrameInSuperViewCenterWithSize:(CGSize)size; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/MSSBrowse/UIView+MSSLayout.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+MSSLayout.m 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 15/12/5. 6 | // Copyright © 2015年 于威. All rights reserved. 7 | // 8 | 9 | #import "UIView+MSSLayout.h" 10 | 11 | @implementation UIView (MSSLayout) 12 | 13 | - (CGFloat)mssLeft 14 | { 15 | return CGRectGetMinX(self.frame); 16 | } 17 | 18 | - (CGFloat)mssRight 19 | { 20 | return CGRectGetMaxX(self.frame); 21 | } 22 | 23 | - (CGFloat)mssBottom 24 | { 25 | return CGRectGetMaxY(self.frame); 26 | } 27 | 28 | - (CGFloat)mssTop 29 | { 30 | return CGRectGetMinY(self.frame); 31 | } 32 | 33 | - (CGFloat)mssHeight 34 | { 35 | return CGRectGetHeight(self.frame); 36 | } 37 | 38 | - (CGFloat)mssWidth 39 | { 40 | return CGRectGetWidth(self.frame); 41 | } 42 | 43 | - (void)setMssX:(CGFloat)mssX 44 | { 45 | CGRect rect = self.frame; 46 | rect.origin.x = mssX; 47 | self.frame = rect; 48 | } 49 | 50 | - (void)setMssY:(CGFloat)mssY 51 | { 52 | CGRect rect = self.frame; 53 | rect.origin.y = mssY; 54 | self.frame = rect; 55 | } 56 | 57 | - (void)setMssWidth:(CGFloat)mssWidth 58 | { 59 | CGRect rect = self.frame; 60 | rect.size.width = mssWidth; 61 | self.frame = rect; 62 | } 63 | 64 | - (void)setMssHeight:(CGFloat)mssHeight 65 | { 66 | CGRect rect = self.frame; 67 | rect.size.height = mssHeight; 68 | self.frame = rect; 69 | } 70 | 71 | - (void)mss_setFrameInSuperViewCenterWithSize:(CGSize)size 72 | { 73 | self.frame = CGRectMake((self.superview.mssWidth - size.width) / 2, (self.superview.mssHeight - size.height) / 2, size.width, size.height); 74 | } 75 | 76 | @end 77 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/MSSBrowse/mss_browseLoading@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MSS0306/MSSBrowse/2adc1ef8ea8841848c73a96bbad793a3e150b40d/MSSBrowse/MSSBrowse/MSSBrowse/mss_browseLoading@2x.png -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/MSSBrowse/mss_browseLoading@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MSS0306/MSSBrowse/2adc1ef8ea8841848c73a96bbad793a3e150b40d/MSSBrowse/MSSBrowse/MSSBrowse/mss_browseLoading@3x.png -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/MSSCollectionViewCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // MSSCollectionViewCell.h 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 15/12/6. 6 | // Copyright © 2015年 于威. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MSSCollectionViewCell : UICollectionViewCell 12 | 13 | @property (nonatomic,strong)UIImageView *imageView; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/MSSCollectionViewCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // MSSCollectionViewCell.m 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 15/12/6. 6 | // Copyright © 2015年 于威. All rights reserved. 7 | // 8 | 9 | #import "MSSCollectionViewCell.h" 10 | 11 | @implementation MSSCollectionViewCell 12 | 13 | - (id)initWithFrame:(CGRect)frame 14 | { 15 | self = [super initWithFrame:frame]; 16 | if (self) { 17 | // Initialization code 18 | [self createCell]; 19 | } 20 | return self; 21 | } 22 | 23 | - (void)createCell 24 | { 25 | _imageView = [[UIImageView alloc]initWithFrame:self.contentView.bounds]; 26 | [self.contentView addSubview:_imageView]; 27 | } 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/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 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/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 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/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 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/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 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/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 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/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 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/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 = [UIScreen mainScreen].scale; 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 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/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 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/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 | @autoreleasepool{ 23 | // do not decode animated images 24 | if (image.images) { return image; } 25 | 26 | CGImageRef imageRef = image.CGImage; 27 | 28 | CGImageAlphaInfo alpha = CGImageGetAlphaInfo(imageRef); 29 | BOOL anyAlpha = (alpha == kCGImageAlphaFirst || 30 | alpha == kCGImageAlphaLast || 31 | alpha == kCGImageAlphaPremultipliedFirst || 32 | alpha == kCGImageAlphaPremultipliedLast); 33 | 34 | if (anyAlpha) { return image; } 35 | 36 | size_t width = CGImageGetWidth(imageRef); 37 | size_t height = CGImageGetHeight(imageRef); 38 | 39 | // current 40 | CGColorSpaceModel imageColorSpaceModel = CGColorSpaceGetModel(CGImageGetColorSpace(imageRef)); 41 | CGColorSpaceRef colorspaceRef = CGImageGetColorSpace(imageRef); 42 | 43 | bool unsupportedColorSpace = (imageColorSpaceModel == 0 || imageColorSpaceModel == -1 || imageColorSpaceModel == kCGColorSpaceModelIndexed); 44 | if (unsupportedColorSpace) 45 | colorspaceRef = CGColorSpaceCreateDeviceRGB(); 46 | 47 | CGContextRef context = CGBitmapContextCreate(NULL, width, 48 | height, 49 | CGImageGetBitsPerComponent(imageRef), 50 | 0, 51 | colorspaceRef, 52 | kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst); 53 | 54 | // Draw the image into the context and retrieve the new image, which will now have an alpha layer 55 | CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef); 56 | CGImageRef imageRefWithAlpha = CGBitmapContextCreateImage(context); 57 | UIImage *imageWithAlpha = [UIImage imageWithCGImage:imageRefWithAlpha scale:image.scale orientation:image.imageOrientation]; 58 | 59 | if (unsupportedColorSpace) 60 | CGColorSpaceRelease(colorspaceRef); 61 | 62 | CGContextRelease(context); 63 | CGImageRelease(imageRefWithAlpha); 64 | 65 | return imageWithAlpha; 66 | } 67 | } 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/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 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 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/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 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/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 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/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 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/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 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/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 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/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 | else if (self.finishedCount == self.requestedCount) { 84 | [self reportStatus]; 85 | if (self.completionBlock) { 86 | self.completionBlock(self.finishedCount, self.skippedCount); 87 | self.completionBlock = nil; 88 | } 89 | self.progressBlock = nil; 90 | } 91 | }]; 92 | } 93 | 94 | - (void)reportStatus { 95 | NSUInteger total = [self.prefetchURLs count]; 96 | if ([self.delegate respondsToSelector:@selector(imagePrefetcher:didFinishWithTotalCount:skippedCount:)]) { 97 | [self.delegate imagePrefetcher:self 98 | didFinishWithTotalCount:(total - self.skippedCount) 99 | skippedCount:self.skippedCount 100 | ]; 101 | } 102 | } 103 | 104 | - (void)prefetchURLs:(NSArray *)urls { 105 | [self prefetchURLs:urls progress:nil completed:nil]; 106 | } 107 | 108 | - (void)prefetchURLs:(NSArray *)urls progress:(SDWebImagePrefetcherProgressBlock)progressBlock completed:(SDWebImagePrefetcherCompletionBlock)completionBlock { 109 | [self cancelPrefetching]; // Prevent duplicate prefetch request 110 | self.startedTime = CFAbsoluteTimeGetCurrent(); 111 | self.prefetchURLs = urls; 112 | self.completionBlock = completionBlock; 113 | self.progressBlock = progressBlock; 114 | 115 | __weak SDWebImagePrefetcher *weakSelf = self; 116 | 117 | if (urls.count == 0) { 118 | if (completionBlock) { 119 | completionBlock(0,0); 120 | } 121 | } else { 122 | // http://oleb.net/blog/2013/07/parallelize-for-loops-gcd-dispatch_apply/ 123 | // Optimize the maxConcurrentdownloads for effeciency. Since caching operations are involved that are non-trivial using 124 | // dispatch_apply might be helpful. 125 | 126 | NSInteger maxNumberOfImages = self.prefetchURLs.count; 127 | 128 | dispatch_apply(maxNumberOfImages/self.maxConcurrentDownloads, self.prefetcherQueue, ^(size_t index) { 129 | size_t i = index * self.maxConcurrentDownloads; 130 | size_t stop = i + self.maxConcurrentDownloads; 131 | do { 132 | [weakSelf startPrefetchingAtIndex:i++]; 133 | } while (i < stop); 134 | }); 135 | 136 | // Download remaining images. 137 | for (size_t i = maxNumberOfImages - (maxNumberOfImages % self.maxConcurrentDownloads); i < (size_t)maxNumberOfImages; i++) { 138 | [self startPrefetchingAtIndex:i]; 139 | } 140 | } 141 | } 142 | 143 | - (void)cancelPrefetching { 144 | self.prefetchURLs = nil; 145 | self.skippedCount = 0; 146 | self.requestedCount = 0; 147 | self.finishedCount = 0; 148 | [self.manager cancelAll]; 149 | } 150 | 151 | @end 152 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/SDWebImage/UIButton+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 UIButtonView. 14 | */ 15 | @interface UIButton (WebCache) 16 | 17 | /** 18 | * Get the current image URL. 19 | */ 20 | - (NSURL *)sd_currentImageURL; 21 | 22 | /** 23 | * Get the image URL for a control state. 24 | * 25 | * @param state Which state you want to know the URL for. The values are described in UIControlState. 26 | */ 27 | - (NSURL *)sd_imageURLForState:(UIControlState)state; 28 | 29 | /** 30 | * Set the imageView `image` with an `url`. 31 | * 32 | * The download is asynchronous and cached. 33 | * 34 | * @param url The url for the image. 35 | * @param state The state that uses the specified title. The values are described in UIControlState. 36 | */ 37 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state; 38 | 39 | /** 40 | * Set the imageView `image` with an `url` and a placeholder. 41 | * 42 | * The download is asynchronous and cached. 43 | * 44 | * @param url The url for the image. 45 | * @param state The state that uses the specified title. The values are described in UIControlState. 46 | * @param placeholder The image to be set initially, until the image request finishes. 47 | * @see sd_setImageWithURL:placeholderImage:options: 48 | */ 49 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder; 50 | 51 | /** 52 | * Set the imageView `image` with an `url`, placeholder and custom options. 53 | * 54 | * The download is asynchronous and cached. 55 | * 56 | * @param url The url for the image. 57 | * @param state The state that uses the specified title. The values are described in UIControlState. 58 | * @param placeholder The image to be set initially, until the image request finishes. 59 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. 60 | */ 61 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; 62 | 63 | /** 64 | * Set the imageView `image` with an `url`. 65 | * 66 | * The download is asynchronous and cached. 67 | * 68 | * @param url The url for the image. 69 | * @param state The state that uses the specified title. The values are described in UIControlState. 70 | * @param completedBlock A block called when operation has been completed. This block has no return value 71 | * and takes the requested UIImage as first parameter. In case of error the image parameter 72 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 73 | * indicating if the image was retrieved from the local cache or from the network. 74 | * The fourth parameter is the original image url. 75 | */ 76 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock; 77 | 78 | /** 79 | * Set the imageView `image` with an `url`, placeholder. 80 | * 81 | * The download is asynchronous and cached. 82 | * 83 | * @param url The url for the image. 84 | * @param state The state that uses the specified title. The values are described in UIControlState. 85 | * @param placeholder The image to be set initially, until the image request finishes. 86 | * @param completedBlock A block called when operation has been completed. This block has no return value 87 | * and takes the requested UIImage as first parameter. In case of error the image parameter 88 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 89 | * indicating if the image was retrieved from the local cache or from the network. 90 | * The fourth parameter is the original image url. 91 | */ 92 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; 93 | 94 | /** 95 | * Set the imageView `image` with an `url`, placeholder and custom options. 96 | * 97 | * The download is asynchronous and cached. 98 | * 99 | * @param url The url for the image. 100 | * @param state The state that uses the specified title. The values are described in UIControlState. 101 | * @param placeholder The image to be set initially, until the image request finishes. 102 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. 103 | * @param completedBlock A block called when operation has been completed. This block has no return value 104 | * and takes the requested UIImage as first parameter. In case of error the image parameter 105 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 106 | * indicating if the image was retrieved from the local cache or from the network. 107 | * The fourth parameter is the original image url. 108 | */ 109 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; 110 | 111 | /** 112 | * Set the backgroundImageView `image` with an `url`. 113 | * 114 | * The download is asynchronous and cached. 115 | * 116 | * @param url The url for the image. 117 | * @param state The state that uses the specified title. The values are described in UIControlState. 118 | */ 119 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state; 120 | 121 | /** 122 | * Set the backgroundImageView `image` with an `url` and a placeholder. 123 | * 124 | * The download is asynchronous and cached. 125 | * 126 | * @param url The url for the image. 127 | * @param state The state that uses the specified title. The values are described in UIControlState. 128 | * @param placeholder The image to be set initially, until the image request finishes. 129 | * @see sd_setImageWithURL:placeholderImage:options: 130 | */ 131 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder; 132 | 133 | /** 134 | * Set the backgroundImageView `image` with an `url`, placeholder and custom options. 135 | * 136 | * The download is asynchronous and cached. 137 | * 138 | * @param url The url for the image. 139 | * @param state The state that uses the specified title. The values are described in UIControlState. 140 | * @param placeholder The image to be set initially, until the image request finishes. 141 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. 142 | */ 143 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options; 144 | 145 | /** 146 | * Set the backgroundImageView `image` with an `url`. 147 | * 148 | * The download is asynchronous and cached. 149 | * 150 | * @param url The url for the image. 151 | * @param state The state that uses the specified title. The values are described in UIControlState. 152 | * @param completedBlock A block called when operation has been completed. This block has no return value 153 | * and takes the requested UIImage as first parameter. In case of error the image parameter 154 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 155 | * indicating if the image was retrieved from the local cache or from the network. 156 | * The fourth parameter is the original image url. 157 | */ 158 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock; 159 | 160 | /** 161 | * Set the backgroundImageView `image` with an `url`, placeholder. 162 | * 163 | * The download is asynchronous and cached. 164 | * 165 | * @param url The url for the image. 166 | * @param state The state that uses the specified title. The values are described in UIControlState. 167 | * @param placeholder The image to be set initially, until the image request finishes. 168 | * @param completedBlock A block called when operation has been completed. This block has no return value 169 | * and takes the requested UIImage as first parameter. In case of error the image parameter 170 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 171 | * indicating if the image was retrieved from the local cache or from the network. 172 | * The fourth parameter is the original image url. 173 | */ 174 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock; 175 | 176 | /** 177 | * Set the backgroundImageView `image` with an `url`, placeholder and custom options. 178 | * 179 | * The download is asynchronous and cached. 180 | * 181 | * @param url The url for the image. 182 | * @param placeholder The image to be set initially, until the image request finishes. 183 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values. 184 | * @param completedBlock A block called when operation has been completed. This block has no return value 185 | * and takes the requested UIImage as first parameter. In case of error the image parameter 186 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 187 | * indicating if the image was retrieved from the local cache or from the network. 188 | * The fourth parameter is the original image url. 189 | */ 190 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock; 191 | 192 | /** 193 | * Cancel the current image download 194 | */ 195 | - (void)sd_cancelImageLoadForState:(UIControlState)state; 196 | 197 | /** 198 | * Cancel the current backgroundImage download 199 | */ 200 | - (void)sd_cancelBackgroundImageLoadForState:(UIControlState)state; 201 | 202 | @end 203 | 204 | 205 | @interface UIButton (WebCacheDeprecated) 206 | 207 | - (NSURL *)currentImageURL __deprecated_msg("Use `sd_currentImageURL`"); 208 | - (NSURL *)imageURLForState:(UIControlState)state __deprecated_msg("Use `sd_imageURLForState:`"); 209 | 210 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:`"); 211 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:`"); 212 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:options:`"); 213 | 214 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:completed:`"); 215 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:completed:`"); 216 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:options:completed:`"); 217 | 218 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:`"); 219 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:`"); 220 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:options:`"); 221 | 222 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:completed:`"); 223 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:completed:`"); 224 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:options:completed:`"); 225 | 226 | - (void)cancelCurrentImageLoad __deprecated_msg("Use `sd_cancelImageLoadForState:`"); 227 | - (void)cancelBackgroundImageLoadForState:(UIControlState)state __deprecated_msg("Use `sd_cancelBackgroundImageLoadForState:`"); 228 | 229 | @end 230 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/SDWebImage/UIButton+WebCache.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 "UIButton+WebCache.h" 10 | #import "objc/runtime.h" 11 | #import "UIView+WebCacheOperation.h" 12 | 13 | static char imageURLStorageKey; 14 | 15 | @implementation UIButton (WebCache) 16 | 17 | - (NSURL *)sd_currentImageURL { 18 | NSURL *url = self.imageURLStorage[@(self.state)]; 19 | 20 | if (!url) { 21 | url = self.imageURLStorage[@(UIControlStateNormal)]; 22 | } 23 | 24 | return url; 25 | } 26 | 27 | - (NSURL *)sd_imageURLForState:(UIControlState)state { 28 | return self.imageURLStorage[@(state)]; 29 | } 30 | 31 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state { 32 | [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; 33 | } 34 | 35 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { 36 | [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; 37 | } 38 | 39 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { 40 | [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; 41 | } 42 | 43 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock { 44 | [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock]; 45 | } 46 | 47 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock { 48 | [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock]; 49 | } 50 | 51 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { 52 | 53 | [self setImage:placeholder forState:state]; 54 | [self sd_cancelImageLoadForState:state]; 55 | 56 | if (!url) { 57 | [self.imageURLStorage removeObjectForKey:@(state)]; 58 | 59 | dispatch_main_async_safe(^{ 60 | NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; 61 | if (completedBlock) { 62 | completedBlock(nil, error, SDImageCacheTypeNone, url); 63 | } 64 | }); 65 | 66 | return; 67 | } 68 | 69 | self.imageURLStorage[@(state)] = url; 70 | 71 | __weak __typeof(self)wself = self; 72 | id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { 73 | if (!wself) return; 74 | dispatch_main_sync_safe(^{ 75 | __strong UIButton *sself = wself; 76 | if (!sself) return; 77 | if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock) 78 | { 79 | completedBlock(image, error, cacheType, url); 80 | return; 81 | } 82 | else if (image) { 83 | [sself setImage:image forState:state]; 84 | } 85 | if (completedBlock && finished) { 86 | completedBlock(image, error, cacheType, url); 87 | } 88 | }); 89 | }]; 90 | [self sd_setImageLoadOperation:operation forState:state]; 91 | } 92 | 93 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state { 94 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; 95 | } 96 | 97 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { 98 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; 99 | } 100 | 101 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { 102 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; 103 | } 104 | 105 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock { 106 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock]; 107 | } 108 | 109 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock { 110 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock]; 111 | } 112 | 113 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { 114 | [self sd_cancelImageLoadForState:state]; 115 | 116 | [self setBackgroundImage:placeholder forState:state]; 117 | 118 | if (url) { 119 | __weak __typeof(self)wself = self; 120 | id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { 121 | if (!wself) return; 122 | dispatch_main_sync_safe(^{ 123 | __strong UIButton *sself = wself; 124 | if (!sself) return; 125 | if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock) 126 | { 127 | completedBlock(image, error, cacheType, url); 128 | return; 129 | } 130 | else if (image) { 131 | [sself setBackgroundImage:image forState:state]; 132 | } 133 | if (completedBlock && finished) { 134 | completedBlock(image, error, cacheType, url); 135 | } 136 | }); 137 | }]; 138 | [self sd_setBackgroundImageLoadOperation:operation forState:state]; 139 | } else { 140 | dispatch_main_async_safe(^{ 141 | NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; 142 | if (completedBlock) { 143 | completedBlock(nil, error, SDImageCacheTypeNone, url); 144 | } 145 | }); 146 | } 147 | } 148 | 149 | - (void)sd_setImageLoadOperation:(id)operation forState:(UIControlState)state { 150 | [self sd_setImageLoadOperation:operation forKey:[NSString stringWithFormat:@"UIButtonImageOperation%@", @(state)]]; 151 | } 152 | 153 | - (void)sd_cancelImageLoadForState:(UIControlState)state { 154 | [self sd_cancelImageLoadOperationWithKey:[NSString stringWithFormat:@"UIButtonImageOperation%@", @(state)]]; 155 | } 156 | 157 | - (void)sd_setBackgroundImageLoadOperation:(id)operation forState:(UIControlState)state { 158 | [self sd_setImageLoadOperation:operation forKey:[NSString stringWithFormat:@"UIButtonBackgroundImageOperation%@", @(state)]]; 159 | } 160 | 161 | - (void)sd_cancelBackgroundImageLoadForState:(UIControlState)state { 162 | [self sd_cancelImageLoadOperationWithKey:[NSString stringWithFormat:@"UIButtonBackgroundImageOperation%@", @(state)]]; 163 | } 164 | 165 | - (NSMutableDictionary *)imageURLStorage { 166 | NSMutableDictionary *storage = objc_getAssociatedObject(self, &imageURLStorageKey); 167 | if (!storage) 168 | { 169 | storage = [NSMutableDictionary dictionary]; 170 | objc_setAssociatedObject(self, &imageURLStorageKey, storage, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 171 | } 172 | 173 | return storage; 174 | } 175 | 176 | @end 177 | 178 | 179 | @implementation UIButton (WebCacheDeprecated) 180 | 181 | - (NSURL *)currentImageURL { 182 | return [self sd_currentImageURL]; 183 | } 184 | 185 | - (NSURL *)imageURLForState:(UIControlState)state { 186 | return [self sd_imageURLForState:state]; 187 | } 188 | 189 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state { 190 | [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; 191 | } 192 | 193 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { 194 | [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; 195 | } 196 | 197 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { 198 | [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; 199 | } 200 | 201 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock { 202 | [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 203 | if (completedBlock) { 204 | completedBlock(image, error, cacheType); 205 | } 206 | }]; 207 | } 208 | 209 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock { 210 | [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 211 | if (completedBlock) { 212 | completedBlock(image, error, cacheType); 213 | } 214 | }]; 215 | } 216 | 217 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { 218 | [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 219 | if (completedBlock) { 220 | completedBlock(image, error, cacheType); 221 | } 222 | }]; 223 | } 224 | 225 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state { 226 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; 227 | } 228 | 229 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { 230 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; 231 | } 232 | 233 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { 234 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; 235 | } 236 | 237 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock { 238 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 239 | if (completedBlock) { 240 | completedBlock(image, error, cacheType); 241 | } 242 | }]; 243 | } 244 | 245 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock { 246 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 247 | if (completedBlock) { 248 | completedBlock(image, error, cacheType); 249 | } 250 | }]; 251 | } 252 | 253 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { 254 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 255 | if (completedBlock) { 256 | completedBlock(image, error, cacheType); 257 | } 258 | }]; 259 | } 260 | 261 | - (void)cancelCurrentImageLoad { 262 | // in a backwards compatible manner, cancel for current state 263 | [self sd_cancelImageLoadForState:self.state]; 264 | } 265 | 266 | - (void)cancelBackgroundImageLoadForState:(UIControlState)state { 267 | [self sd_cancelBackgroundImageLoadForState:state]; 268 | } 269 | 270 | @end 271 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/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 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/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 | 36 | duration += [self sd_frameDurationAtIndex:i source:source]; 37 | 38 | [images addObject:[UIImage imageWithCGImage:image scale:[UIScreen mainScreen].scale orientation:UIImageOrientationUp]]; 39 | 40 | CGImageRelease(image); 41 | } 42 | 43 | if (!duration) { 44 | duration = (1.0f / 10.0f) * count; 45 | } 46 | 47 | animatedImage = [UIImage animatedImageWithImages:images duration:duration]; 48 | } 49 | 50 | CFRelease(source); 51 | 52 | return animatedImage; 53 | } 54 | 55 | + (float)sd_frameDurationAtIndex:(NSUInteger)index source:(CGImageSourceRef)source { 56 | float frameDuration = 0.1f; 57 | CFDictionaryRef cfFrameProperties = CGImageSourceCopyPropertiesAtIndex(source, index, nil); 58 | NSDictionary *frameProperties = (__bridge NSDictionary *)cfFrameProperties; 59 | NSDictionary *gifProperties = frameProperties[(NSString *)kCGImagePropertyGIFDictionary]; 60 | 61 | NSNumber *delayTimeUnclampedProp = gifProperties[(NSString *)kCGImagePropertyGIFUnclampedDelayTime]; 62 | if (delayTimeUnclampedProp) { 63 | frameDuration = [delayTimeUnclampedProp floatValue]; 64 | } 65 | else { 66 | 67 | NSNumber *delayTimeProp = gifProperties[(NSString *)kCGImagePropertyGIFDelayTime]; 68 | if (delayTimeProp) { 69 | frameDuration = [delayTimeProp floatValue]; 70 | } 71 | } 72 | 73 | // Many annoying ads specify a 0 duration to make an image flash as quickly as possible. 74 | // We follow Firefox's behavior and use a duration of 100 ms for any frames that specify 75 | // a duration of <= 10 ms. See and 76 | // for more information. 77 | 78 | if (frameDuration < 0.011f) { 79 | frameDuration = 0.100f; 80 | } 81 | 82 | CFRelease(cfFrameProperties); 83 | return frameDuration; 84 | } 85 | 86 | + (UIImage *)sd_animatedGIFNamed:(NSString *)name { 87 | CGFloat scale = [UIScreen mainScreen].scale; 88 | 89 | if (scale > 1.0f) { 90 | NSString *retinaPath = [[NSBundle mainBundle] pathForResource:[name stringByAppendingString:@"@2x"] ofType:@"gif"]; 91 | 92 | NSData *data = [NSData dataWithContentsOfFile:retinaPath]; 93 | 94 | if (data) { 95 | return [UIImage sd_animatedGIFWithData:data]; 96 | } 97 | 98 | NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"gif"]; 99 | 100 | data = [NSData dataWithContentsOfFile:path]; 101 | 102 | if (data) { 103 | return [UIImage sd_animatedGIFWithData:data]; 104 | } 105 | 106 | return [UIImage imageNamed:name]; 107 | } 108 | else { 109 | NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"gif"]; 110 | 111 | NSData *data = [NSData dataWithContentsOfFile:path]; 112 | 113 | if (data) { 114 | return [UIImage sd_animatedGIFWithData:data]; 115 | } 116 | 117 | return [UIImage imageNamed:name]; 118 | } 119 | } 120 | 121 | - (UIImage *)sd_animatedImageByScalingAndCroppingToSize:(CGSize)size { 122 | if (CGSizeEqualToSize(self.size, size) || CGSizeEqualToSize(size, CGSizeZero)) { 123 | return self; 124 | } 125 | 126 | CGSize scaledSize = size; 127 | CGPoint thumbnailPoint = CGPointZero; 128 | 129 | CGFloat widthFactor = size.width / self.size.width; 130 | CGFloat heightFactor = size.height / self.size.height; 131 | CGFloat scaleFactor = (widthFactor > heightFactor) ? widthFactor : heightFactor; 132 | scaledSize.width = self.size.width * scaleFactor; 133 | scaledSize.height = self.size.height * scaleFactor; 134 | 135 | if (widthFactor > heightFactor) { 136 | thumbnailPoint.y = (size.height - scaledSize.height) * 0.5; 137 | } 138 | else if (widthFactor < heightFactor) { 139 | thumbnailPoint.x = (size.width - scaledSize.width) * 0.5; 140 | } 141 | 142 | NSMutableArray *scaledImages = [NSMutableArray array]; 143 | 144 | for (UIImage *image in self.images) { 145 | UIGraphicsBeginImageContextWithOptions(size, NO, 0.0); 146 | 147 | [image drawInRect:CGRectMake(thumbnailPoint.x, thumbnailPoint.y, scaledSize.width, scaledSize.height)]; 148 | UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 149 | 150 | [scaledImages addObject:newImage]; 151 | 152 | UIGraphicsEndImageContext(); 153 | } 154 | 155 | return [UIImage animatedImageWithImages:scaledImages duration:self.duration]; 156 | } 157 | 158 | @end 159 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/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 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/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 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/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 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/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 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/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 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/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 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/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 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/SDWebImage/UIImageView+WebCache.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+WebCache.h" 10 | #import "objc/runtime.h" 11 | #import "UIView+WebCacheOperation.h" 12 | 13 | static char imageURLKey; 14 | static char TAG_ACTIVITY_INDICATOR; 15 | static char TAG_ACTIVITY_STYLE; 16 | static char TAG_ACTIVITY_SHOW; 17 | 18 | @implementation UIImageView (WebCache) 19 | 20 | - (void)sd_setImageWithURL:(NSURL *)url { 21 | [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil]; 22 | } 23 | 24 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder { 25 | [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil]; 26 | } 27 | 28 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { 29 | [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil]; 30 | } 31 | 32 | - (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock { 33 | [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:completedBlock]; 34 | } 35 | 36 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock { 37 | [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:completedBlock]; 38 | } 39 | 40 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock { 41 | [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:completedBlock]; 42 | } 43 | 44 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock { 45 | [self sd_cancelCurrentImageLoad]; 46 | objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 47 | 48 | if (!(options & SDWebImageDelayPlaceholder)) { 49 | dispatch_main_async_safe(^{ 50 | self.image = placeholder; 51 | }); 52 | } 53 | 54 | if (url) { 55 | 56 | // check if activityView is enabled or not 57 | if ([self showActivityIndicatorView]) { 58 | [self addActivityIndicator]; 59 | } 60 | 61 | __weak __typeof(self)wself = self; 62 | id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { 63 | [wself removeActivityIndicator]; 64 | if (!wself) return; 65 | dispatch_main_sync_safe(^{ 66 | if (!wself) return; 67 | if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock) 68 | { 69 | completedBlock(image, error, cacheType, url); 70 | return; 71 | } 72 | else if (image) { 73 | wself.image = image; 74 | [wself setNeedsLayout]; 75 | } else { 76 | if ((options & SDWebImageDelayPlaceholder)) { 77 | wself.image = placeholder; 78 | [wself setNeedsLayout]; 79 | } 80 | } 81 | if (completedBlock && finished) { 82 | completedBlock(image, error, cacheType, url); 83 | } 84 | }); 85 | }]; 86 | [self sd_setImageLoadOperation:operation forKey:@"UIImageViewImageLoad"]; 87 | } else { 88 | dispatch_main_async_safe(^{ 89 | [self removeActivityIndicator]; 90 | NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; 91 | if (completedBlock) { 92 | completedBlock(nil, error, SDImageCacheTypeNone, url); 93 | } 94 | }); 95 | } 96 | } 97 | 98 | - (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock { 99 | NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:url]; 100 | UIImage *lastPreviousCachedImage = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:key]; 101 | 102 | [self sd_setImageWithURL:url placeholderImage:lastPreviousCachedImage ?: placeholder options:options progress:progressBlock completed:completedBlock]; 103 | } 104 | 105 | - (NSURL *)sd_imageURL { 106 | return objc_getAssociatedObject(self, &imageURLKey); 107 | } 108 | 109 | - (void)sd_setAnimationImagesWithURLs:(NSArray *)arrayOfURLs { 110 | [self sd_cancelCurrentAnimationImagesLoad]; 111 | __weak __typeof(self)wself = self; 112 | 113 | NSMutableArray *operationsArray = [[NSMutableArray alloc] init]; 114 | 115 | for (NSURL *logoImageURL in arrayOfURLs) { 116 | id operation = [SDWebImageManager.sharedManager downloadImageWithURL:logoImageURL options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { 117 | if (!wself) return; 118 | dispatch_main_sync_safe(^{ 119 | __strong UIImageView *sself = wself; 120 | [sself stopAnimating]; 121 | if (sself && image) { 122 | NSMutableArray *currentImages = [[sself animationImages] mutableCopy]; 123 | if (!currentImages) { 124 | currentImages = [[NSMutableArray alloc] init]; 125 | } 126 | [currentImages addObject:image]; 127 | 128 | sself.animationImages = currentImages; 129 | [sself setNeedsLayout]; 130 | } 131 | [sself startAnimating]; 132 | }); 133 | }]; 134 | [operationsArray addObject:operation]; 135 | } 136 | 137 | [self sd_setImageLoadOperation:[NSArray arrayWithArray:operationsArray] forKey:@"UIImageViewAnimationImages"]; 138 | } 139 | 140 | - (void)sd_cancelCurrentImageLoad { 141 | [self sd_cancelImageLoadOperationWithKey:@"UIImageViewImageLoad"]; 142 | } 143 | 144 | - (void)sd_cancelCurrentAnimationImagesLoad { 145 | [self sd_cancelImageLoadOperationWithKey:@"UIImageViewAnimationImages"]; 146 | } 147 | 148 | 149 | #pragma mark - 150 | - (UIActivityIndicatorView *)activityIndicator { 151 | return (UIActivityIndicatorView *)objc_getAssociatedObject(self, &TAG_ACTIVITY_INDICATOR); 152 | } 153 | 154 | - (void)setActivityIndicator:(UIActivityIndicatorView *)activityIndicator { 155 | objc_setAssociatedObject(self, &TAG_ACTIVITY_INDICATOR, activityIndicator, OBJC_ASSOCIATION_RETAIN); 156 | } 157 | 158 | - (void)setShowActivityIndicatorView:(BOOL)show{ 159 | objc_setAssociatedObject(self, &TAG_ACTIVITY_SHOW, [NSNumber numberWithBool:show], OBJC_ASSOCIATION_RETAIN); 160 | } 161 | 162 | - (BOOL)showActivityIndicatorView{ 163 | return [objc_getAssociatedObject(self, &TAG_ACTIVITY_SHOW) boolValue]; 164 | } 165 | 166 | - (void)setIndicatorStyle:(UIActivityIndicatorViewStyle)style{ 167 | objc_setAssociatedObject(self, &TAG_ACTIVITY_STYLE, [NSNumber numberWithInt:style], OBJC_ASSOCIATION_RETAIN); 168 | } 169 | 170 | - (int)getIndicatorStyle{ 171 | return [objc_getAssociatedObject(self, &TAG_ACTIVITY_STYLE) intValue]; 172 | } 173 | 174 | - (void)addActivityIndicator { 175 | if (!self.activityIndicator) { 176 | self.activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:[self getIndicatorStyle]]; 177 | self.activityIndicator.translatesAutoresizingMaskIntoConstraints = NO; 178 | 179 | dispatch_main_async_safe(^{ 180 | [self addSubview:self.activityIndicator]; 181 | 182 | [self addConstraint:[NSLayoutConstraint constraintWithItem:self.activityIndicator 183 | attribute:NSLayoutAttributeCenterX 184 | relatedBy:NSLayoutRelationEqual 185 | toItem:self 186 | attribute:NSLayoutAttributeCenterX 187 | multiplier:1.0 188 | constant:0.0]]; 189 | [self addConstraint:[NSLayoutConstraint constraintWithItem:self.activityIndicator 190 | attribute:NSLayoutAttributeCenterY 191 | relatedBy:NSLayoutRelationEqual 192 | toItem:self 193 | attribute:NSLayoutAttributeCenterY 194 | multiplier:1.0 195 | constant:0.0]]; 196 | }); 197 | } 198 | 199 | dispatch_main_async_safe(^{ 200 | [self.activityIndicator startAnimating]; 201 | }); 202 | 203 | } 204 | 205 | - (void)removeActivityIndicator { 206 | if (self.activityIndicator) { 207 | [self.activityIndicator removeFromSuperview]; 208 | self.activityIndicator = nil; 209 | } 210 | } 211 | 212 | @end 213 | 214 | 215 | @implementation UIImageView (WebCacheDeprecated) 216 | 217 | - (NSURL *)imageURL { 218 | return [self sd_imageURL]; 219 | } 220 | 221 | - (void)setImageWithURL:(NSURL *)url { 222 | [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil]; 223 | } 224 | 225 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder { 226 | [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil]; 227 | } 228 | 229 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options { 230 | [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil]; 231 | } 232 | 233 | - (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock { 234 | [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 235 | if (completedBlock) { 236 | completedBlock(image, error, cacheType); 237 | } 238 | }]; 239 | } 240 | 241 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock { 242 | [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 243 | if (completedBlock) { 244 | completedBlock(image, error, cacheType); 245 | } 246 | }]; 247 | } 248 | 249 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock { 250 | [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 251 | if (completedBlock) { 252 | completedBlock(image, error, cacheType); 253 | } 254 | }]; 255 | } 256 | 257 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock { 258 | [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 259 | if (completedBlock) { 260 | completedBlock(image, error, cacheType); 261 | } 262 | }]; 263 | } 264 | 265 | - (void)cancelCurrentArrayLoad { 266 | [self sd_cancelCurrentAnimationImagesLoad]; 267 | } 268 | 269 | - (void)cancelCurrentImageLoad { 270 | [self sd_cancelCurrentImageLoad]; 271 | } 272 | 273 | - (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs { 274 | [self sd_setAnimationImagesWithURLs:arrayOfURLs]; 275 | } 276 | 277 | @end 278 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/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 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/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 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 16/2/27. 6 | // Copyright © 2016年 于威. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 15/12/5. 6 | // Copyright © 2015年 于威. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "MSSBrowseDefine.h" 11 | #import "UIImageView+WebCache.h" 12 | #import "MSSCollectionViewCell.h" 13 | 14 | @interface ViewController () 15 | 16 | @property (nonatomic,strong)UICollectionView *collectionView; 17 | @property (nonatomic,strong)NSArray *smallUrlArray; 18 | 19 | @end 20 | 21 | @implementation ViewController 22 | 23 | - (void)viewDidLoad { 24 | [super viewDidLoad]; 25 | // Do any additional setup after loading the view, typically from a nib. 26 | 27 | self.view.backgroundColor = [UIColor orangeColor]; 28 | 29 | UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; 30 | btn.frame = CGRectMake(10, 70, 100, 50); 31 | btn.backgroundColor = [UIColor blackColor]; 32 | [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside]; 33 | [btn setTitle:@"清空缓存" forState:UIControlStateNormal]; 34 | [self.view addSubview:btn]; 35 | 36 | _smallUrlArray = @[@"http://7xjtvh.com1.z0.glb.clouddn.com/browse01_s.jpg", 37 | @"http://7xjtvh.com1.z0.glb.clouddn.com/browse02_s.jpg", 38 | @"http://7xjtvh.com1.z0.glb.clouddn.com/browse03_s.jpg", 39 | @"http://7xjtvh.com1.z0.glb.clouddn.com/browse04_s.jpg", 40 | @"http://7xjtvh.com1.z0.glb.clouddn.com/browse05_s.jpg", 41 | @"http://7xjtvh.com1.z0.glb.clouddn.com/browse06_s.jpg", 42 | @"http://7xjtvh.com1.z0.glb.clouddn.com/browse07_s.jpg", 43 | @"http://7xjtvh.com1.z0.glb.clouddn.com/browse08_s.jpg", 44 | @"http://7xjtvh.com1.z0.glb.clouddn.com/browse09_s.jpg"]; 45 | 46 | UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init]; 47 | flowLayout.minimumLineSpacing = 0; 48 | flowLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10); 49 | flowLayout.itemSize = CGSizeMake(80, 80); 50 | flowLayout.minimumLineSpacing = 10; 51 | 52 | _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, btn.mssBottom, MSS_SCREEN_WIDTH, MSS_SCREEN_HEIGHT - btn.mssBottom) collectionViewLayout:flowLayout]; 53 | _collectionView.delegate = self; 54 | _collectionView.dataSource = self; 55 | _collectionView.backgroundColor = [UIColor clearColor]; 56 | //cell注册 57 | [_collectionView registerClass:[MSSCollectionViewCell class] forCellWithReuseIdentifier:@"MSSCollectionViewCell"]; 58 | [self.view addSubview:_collectionView]; 59 | 60 | } 61 | 62 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 63 | { 64 | return [_smallUrlArray count]; 65 | } 66 | 67 | - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 68 | { 69 | MSSCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MSSCollectionViewCell" forIndexPath:indexPath]; 70 | if (cell) 71 | { 72 | [cell.imageView sd_setImageWithURL:[NSURL URLWithString:_smallUrlArray[indexPath.row]]]; 73 | cell.imageView.tag = indexPath.row + 100; 74 | cell.imageView.contentMode = UIViewContentModeScaleAspectFill; 75 | cell.imageView.clipsToBounds = YES; 76 | } 77 | return cell; 78 | } 79 | 80 | - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 81 | { 82 | NSArray *bigUrlArray = @[@"http://7xjtvh.com1.z0.glb.clouddn.com/browse01.jpg", 83 | @"http://7xjtvh.com1.z0.glb.clouddn.com/browse02.jpg", 84 | @"http://7xjtvh.com1.z0.glb.clouddn.com/browse03.jpg", 85 | @"http://7xjtvh.com1.z0.glb.clouddn.com/browse04.jpg", 86 | @"http://7xjtvh.com1.z0.glb.clouddn.com/browse05.jpg", 87 | @"http://7xjtvh.com1.z0.glb.clouddn.com/browse06.jpg", 88 | @"http://7xjtvh.com1.z0.glb.clouddn.com/browse07.jpg", 89 | @"http://7xjtvh.com1.z0.glb.clouddn.com/browse08.jpg", 90 | @"http://7xjtvh.com1.z0.glb.clouddn.com/browse09.jpg"]; 91 | // 加载网络图片 92 | NSMutableArray *browseItemArray = [[NSMutableArray alloc]init]; 93 | int i = 0; 94 | for(i = 0;i < [_smallUrlArray count];i++) 95 | { 96 | UIImageView *imageView = [self.view viewWithTag:i + 100]; 97 | MSSBrowseModel *browseItem = [[MSSBrowseModel alloc]init]; 98 | browseItem.bigImageUrl = bigUrlArray[i];// 加载网络图片大图地址 99 | browseItem.smallImageView = imageView;// 小图 100 | [browseItemArray addObject:browseItem]; 101 | } 102 | MSSCollectionViewCell *cell = (MSSCollectionViewCell *)[_collectionView cellForItemAtIndexPath:indexPath]; 103 | MSSBrowseNetworkViewController *bvc = [[MSSBrowseNetworkViewController alloc]initWithBrowseItemArray:browseItemArray currentIndex:cell.imageView.tag - 100]; 104 | // bvc.isEqualRatio = NO;// 大图小图不等比时需要设置这个属性(建议等比) 105 | [bvc showBrowseViewController]; 106 | 107 | // // 加载本地图片 108 | // NSMutableArray *browseItemArray = [[NSMutableArray alloc]init]; 109 | // int i = 0; 110 | // for(i = 0;i < [_smallUrlArray count];i++) 111 | // { 112 | // UIImageView *imageView = [self.view viewWithTag:i + 100]; 113 | // MSSBrowseModel *browseItem = [[MSSBrowseModel alloc]init]; 114 | //// browseItem.bigImageLocalPath 建议传本地图片的路径来减少内存使用 115 | // browseItem.bigImage = imageView.image;// 大图赋值 116 | // browseItem.smallImageView = imageView;// 小图 117 | // [browseItemArray addObject:browseItem]; 118 | // } 119 | // MSSCollectionViewCell *cell = (MSSCollectionViewCell *)[_collectionView cellForItemAtIndexPath:indexPath]; 120 | // MSSBrowseLocalViewController *bvc = [[MSSBrowseLocalViewController alloc]initWithBrowseItemArray:browseItemArray currentIndex:cell.imageView.tag - 100]; 121 | // [bvc showBrowseViewController]; 122 | } 123 | 124 | 125 | - (void)btnClick 126 | { 127 | [[SDImageCache sharedImageCache]clearMemory]; 128 | [[SDImageCache sharedImageCache]clearDiskOnCompletion:^{ 129 | [_collectionView reloadData]; 130 | }]; 131 | } 132 | 133 | - (void)didReceiveMemoryWarning { 134 | [super didReceiveMemoryWarning]; 135 | // Dispose of any resources that can be recreated. 136 | } 137 | 138 | @end 139 | -------------------------------------------------------------------------------- /MSSBrowse/MSSBrowse/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // MSSBrowse 4 | // 5 | // Created by 于威 on 16/2/27. 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MSSBrowse 2 | A simple iOS photo browse like wechat 微信图片浏览 3 | 4 | ![效果图](https://raw.githubusercontent.com/MSS0306/MSSBrowse/master/browse.gif) 5 | 6 | # 说明 7 | 1.支持图片横屏浏览(您不需要开启横屏,因为是利用view的旋转做的横屏浏览效果,完美解决主流应用不支持横屏的问题)
8 | 2.强烈建议小图和大图为等比缩放的图片
9 | 3.动画浏览图片,类似微信的效果
10 | 4.长按手势弹框可保存图片,复制图片地址
11 | 5.支持双击和捏合手势放大和缩小图片
12 | 6.支持最低版本iOS7.0 13 | 14 | # 版本2.2 15 | 1.修复加载动画复用圆圈变形问题
16 | 2.修复小图不存在时,大图加载不出来问题 17 | 18 | # 版本2.1 19 | 1.添加浏览本地图片 20 | 21 | # 版本2.0 22 | 1.放弃Autolayout,利用view的transform支持单个浏览页的横屏
23 | 2.双击图片放大缩小添加
24 | 3.长按手势弹框保存图片
25 | 4.部分代码优化 26 | 27 | # 版本1.2 28 | 1.适配iOS7横屏显示错乱的问题
29 | 2.随主流应用,只有浏览图片页才可以横屏
30 | 3.解决加载本地图片第一次会闪一下的bug 31 | 32 | # 版本1.1 33 | 1.添加横竖屏(Masonry布局)
34 | 2.修改了图片加载错乱的bug
35 | 3.View改为ViewController控制
36 | 4.关闭图片浏览view的时候,不需要继续执行小图加载大图动画
37 | 5.修复转换坐标不准确问题 38 | 39 | #Example 40 | 1.加载网络图片
41 | ```Objective-c 42 | - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 43 | { 44 | NSArray *bigUrlArray = @[@"http://7xjtvh.com1.z0.glb.clouddn.com/browse01.jpg", 45 | @"http://7xjtvh.com1.z0.glb.clouddn.com/browse02.jpg", 46 | @"http://7xjtvh.com1.z0.glb.clouddn.com/browse03.jpg", 47 | @"http://7xjtvh.com1.z0.glb.clouddn.com/browse04.jpg", 48 | @"http://7xjtvh.com1.z0.glb.clouddn.com/browse05.jpg", 49 | @"http://7xjtvh.com1.z0.glb.clouddn.com/browse06.jpg", 50 | @"http://7xjtvh.com1.z0.glb.clouddn.com/browse07.jpg", 51 | @"http://7xjtvh.com1.z0.glb.clouddn.com/browse08.jpg", 52 | @"http://7xjtvh.com1.z0.glb.clouddn.com/browse09.jpg"]; 53 | // 加载网络图片 54 | NSMutableArray *browseItemArray = [[NSMutableArray alloc]init]; 55 | int i = 0; 56 | for(i = 0;i < [_smallUrlArray count];i++) 57 | { 58 | UIImageView *imageView = [self.view viewWithTag:i + 100]; 59 | MSSBrowseModel *browseItem = [[MSSBrowseModel alloc]init]; 60 | browseItem.bigImageUrl = bigUrlArray[i];// 加载网络图片大图地址 61 | browseItem.smallImageView = imageView;// 小图 62 | [browseItemArray addObject:browseItem]; 63 | } 64 | MSSCollectionViewCell *cell = (MSSCollectionViewCell *)[_collectionView cellForItemAtIndexPath:indexPath]; 65 | MSSBrowseNetworkViewController *bvc = [[MSSBrowseNetworkViewController alloc]initWithBrowseItemArray:browseItemArray currentIndex:cell.imageView.tag - 100]; 66 | // bvc.isEqualRatio = NO;// 大图小图不等比时需要设置这个属性(建议等比) 67 | [bvc showBrowseViewController]; 68 | } 69 | ``` 70 |
71 | 2.加载本地图片
72 | ```Objective-c 73 | - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 74 | { 75 | // 加载本地图片 76 | NSMutableArray *browseItemArray = [[NSMutableArray alloc]init]; 77 | int i = 0; 78 | for(i = 0;i < [_smallUrlArray count];i++) 79 | { 80 | UIImageView *imageView = [self.view viewWithTag:i + 100]; 81 | MSSBrowseModel *browseItem = [[MSSBrowseModel alloc]init]; 82 | // browseItem.bigImageLocalPath 建议传本地图片的路径来减少内存使用 83 | browseItem.bigImage = imageView.image;// 大图赋值 84 | browseItem.smallImageView = imageView;// 小图 85 | [browseItemArray addObject:browseItem]; 86 | } 87 | MSSCollectionViewCell *cell = (MSSCollectionViewCell *)[_collectionView cellForItemAtIndexPath:indexPath]; 88 | MSSBrowseLocalViewController *bvc = [[MSSBrowseLocalViewController alloc]initWithBrowseItemArray:browseItemArray currentIndex:cell.imageView.tag - 100]; 89 | [bvc showBrowseViewController]; 90 | } 91 | ``` 92 | 93 | -------------------------------------------------------------------------------- /browse.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MSS0306/MSSBrowse/2adc1ef8ea8841848c73a96bbad793a3e150b40d/browse.gif --------------------------------------------------------------------------------