├── .DS_Store ├── .gitignore ├── .swift-version ├── Classes ├── 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 └── XWPublish │ ├── XWImagePicker │ ├── Lib │ │ ├── CollectionViewInfo │ │ │ ├── MFlowLayOut.h │ │ │ ├── MFlowLayOut.m │ │ │ ├── MHeadImaView.h │ │ │ ├── MHeadImaView.m │ │ │ ├── MHeaderImaCell.h │ │ │ └── MHeaderImaCell.m │ │ ├── JJPhotoViewer │ │ │ ├── JJMainScrollView.h │ │ │ ├── JJMainScrollView.m │ │ │ ├── JJOneScrollView.h │ │ │ ├── JJOneScrollView.m │ │ │ ├── JJPhoto.h │ │ │ ├── JJPhoto.m │ │ │ ├── JJPhotoManeger.h │ │ │ ├── JJPhotoManeger.m │ │ │ └── none.png │ │ ├── MImgpicker │ │ │ ├── ImagePickerDefine.h │ │ │ ├── MGroupCell.h │ │ │ ├── MGroupCell.m │ │ │ ├── MGroupCell.xib │ │ │ ├── MImaCell.h │ │ │ ├── MImaCell.m │ │ │ ├── MImaCell.xib │ │ │ ├── MImaLibTool.h │ │ │ ├── MImaLibTool.m │ │ │ ├── MShowAllGroup.h │ │ │ ├── MShowAllGroup.m │ │ │ ├── MShowGroupAllSet.h │ │ │ └── MShowGroupAllSet.m │ │ └── SDProgressView │ │ │ ├── Lib │ │ │ ├── SDBaseProgressView.h │ │ │ ├── SDBaseProgressView.m │ │ │ ├── SDLoopProgressView.h │ │ │ ├── SDLoopProgressView.m │ │ │ └── SDProgressView.h │ │ │ └── View │ │ │ ├── SDDemoItemView.h │ │ │ └── SDDemoItemView.m │ ├── XWImagePickerSheet.h │ └── XWImagePickerSheet.m │ ├── XWPhotoCell.h │ ├── XWPhotoCell.m │ ├── XWPhotoCell.xib │ ├── XWPublishBaseController.h │ ├── XWPublishBaseController.m │ ├── XWPublishController.h │ ├── XWPublishController.m │ ├── XWPublishController.xib │ └── images │ ├── close.png │ ├── close@2x.png │ ├── close@3x.png │ ├── ico_check_nomal.png │ ├── ico_check_nomal@2x.png │ ├── ico_check_nomal@3x.png │ ├── ico_check_select.png │ ├── ico_check_select@2x.png │ ├── ico_check_select@3x.png │ ├── plus.png │ ├── plus@2x.png │ └── plus@3x.png ├── LICENSE ├── README.md ├── XWPublish.podspec ├── XWPublishDemo ├── .DS_Store ├── XWPublishDemo.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata └── XWPublishDemo │ ├── .DS_Store │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── 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 │ ├── XWPublish │ ├── XWImagePicker │ │ ├── Lib │ │ │ ├── CollectionViewInfo │ │ │ │ ├── MFlowLayOut.h │ │ │ │ ├── MFlowLayOut.m │ │ │ │ ├── MHeadImaView.h │ │ │ │ ├── MHeadImaView.m │ │ │ │ ├── MHeaderImaCell.h │ │ │ │ └── MHeaderImaCell.m │ │ │ ├── JJPhotoViewer │ │ │ │ ├── JJMainScrollView.h │ │ │ │ ├── JJMainScrollView.m │ │ │ │ ├── JJOneScrollView.h │ │ │ │ ├── JJOneScrollView.m │ │ │ │ ├── JJPhoto.h │ │ │ │ ├── JJPhoto.m │ │ │ │ ├── JJPhotoManeger.h │ │ │ │ ├── JJPhotoManeger.m │ │ │ │ └── none.png │ │ │ ├── MImgpicker │ │ │ │ ├── ImagePickerDefine.h │ │ │ │ ├── MGroupCell.h │ │ │ │ ├── MGroupCell.m │ │ │ │ ├── MGroupCell.xib │ │ │ │ ├── MImaCell.h │ │ │ │ ├── MImaCell.m │ │ │ │ ├── MImaCell.xib │ │ │ │ ├── MImaLibTool.h │ │ │ │ ├── MImaLibTool.m │ │ │ │ ├── MShowAllGroup.h │ │ │ │ ├── MShowAllGroup.m │ │ │ │ ├── MShowGroupAllSet.h │ │ │ │ └── MShowGroupAllSet.m │ │ │ └── SDProgressView │ │ │ │ ├── Lib │ │ │ │ ├── SDBaseProgressView.h │ │ │ │ ├── SDBaseProgressView.m │ │ │ │ ├── SDLoopProgressView.h │ │ │ │ ├── SDLoopProgressView.m │ │ │ │ └── SDProgressView.h │ │ │ │ └── View │ │ │ │ ├── SDDemoItemView.h │ │ │ │ └── SDDemoItemView.m │ │ ├── XWImagePickerSheet.h │ │ └── XWImagePickerSheet.m │ ├── XWPhotoCell.h │ ├── XWPhotoCell.m │ ├── XWPhotoCell.xib │ ├── XWPublishBaseController.h │ ├── XWPublishBaseController.m │ ├── XWPublishController.h │ ├── XWPublishController.m │ ├── XWPublishController.xib │ └── images │ │ ├── close.png │ │ ├── close@2x.png │ │ ├── close@3x.png │ │ ├── ico_check_nomal.png │ │ ├── ico_check_nomal@2x.png │ │ ├── ico_check_nomal@3x.png │ │ ├── ico_check_select.png │ │ ├── ico_check_select@2x.png │ │ ├── ico_check_select@3x.png │ │ ├── plus.png │ │ ├── plus@2x.png │ │ └── plus@3x.png │ └── main.m └── 演示gif └── publicGif.gif /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qxuewei/XWPublish/15f107959ec45c7e9f5a30479f4f21947b069de9/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata 19 | 20 | .DS_Store 21 | .DS_Store? 22 | 23 | ## Other 24 | *.xccheckout 25 | *.moved-aside 26 | *.xcuserstate 27 | *.xcscmblueprint 28 | 29 | ## Obj-C/Swift specific 30 | *.hmap 31 | *.ipa 32 | 33 | # CocoaPods 34 | # 35 | # We recommend against adding the Pods directory to your .gitignore. However 36 | # you should judge for yourself, the pros and cons are mentioned at: 37 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 38 | # 39 | # Pods/ 40 | 41 | # Carthage 42 | # 43 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 44 | # Carthage/Checkouts 45 | 46 | Carthage/Build 47 | 48 | # fastlane 49 | # 50 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 51 | # screenshots whenever they are needed. 52 | # For more information about the recommended setup visit: 53 | # https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md 54 | 55 | fastlane/report.xml 56 | fastlane/screenshots 57 | -------------------------------------------------------------------------------- /.swift-version: -------------------------------------------------------------------------------- 1 | 3.0 2 | -------------------------------------------------------------------------------- /Classes/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 | -------------------------------------------------------------------------------- /Classes/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 | -------------------------------------------------------------------------------- /Classes/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 | -------------------------------------------------------------------------------- /Classes/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 | -------------------------------------------------------------------------------- /Classes/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 | -------------------------------------------------------------------------------- /Classes/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 | -------------------------------------------------------------------------------- /Classes/SDWebImage/SDWebImageDecoder.m: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * Created by james on 9/28/11. 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | #import "SDWebImageDecoder.h" 12 | 13 | @implementation UIImage (ForceDecode) 14 | 15 | + (UIImage *)decodedImageWithImage:(UIImage *)image { 16 | // while downloading huge amount of images 17 | // autorelease the bitmap context 18 | // and all vars to help system to free memory 19 | // when there are memory warning. 20 | // on iOS7, do not forget to call 21 | // [[SDImageCache sharedImageCache] clearMemory]; 22 | 23 | if (image == nil) { // Prevent "CGBitmapContextCreateImage: invalid context 0x0" error 24 | return nil; 25 | } 26 | 27 | @autoreleasepool{ 28 | // do not decode animated images 29 | if (image.images != nil) { 30 | return image; 31 | } 32 | 33 | CGImageRef imageRef = image.CGImage; 34 | 35 | CGImageAlphaInfo alpha = CGImageGetAlphaInfo(imageRef); 36 | BOOL anyAlpha = (alpha == kCGImageAlphaFirst || 37 | alpha == kCGImageAlphaLast || 38 | alpha == kCGImageAlphaPremultipliedFirst || 39 | alpha == kCGImageAlphaPremultipliedLast); 40 | if (anyAlpha) { 41 | return image; 42 | } 43 | 44 | // current 45 | CGColorSpaceModel imageColorSpaceModel = CGColorSpaceGetModel(CGImageGetColorSpace(imageRef)); 46 | CGColorSpaceRef colorspaceRef = CGImageGetColorSpace(imageRef); 47 | 48 | BOOL unsupportedColorSpace = (imageColorSpaceModel == kCGColorSpaceModelUnknown || 49 | imageColorSpaceModel == kCGColorSpaceModelMonochrome || 50 | imageColorSpaceModel == kCGColorSpaceModelCMYK || 51 | imageColorSpaceModel == kCGColorSpaceModelIndexed); 52 | if (unsupportedColorSpace) { 53 | colorspaceRef = CGColorSpaceCreateDeviceRGB(); 54 | } 55 | 56 | size_t width = CGImageGetWidth(imageRef); 57 | size_t height = CGImageGetHeight(imageRef); 58 | NSUInteger bytesPerPixel = 4; 59 | NSUInteger bytesPerRow = bytesPerPixel * width; 60 | NSUInteger bitsPerComponent = 8; 61 | 62 | 63 | // kCGImageAlphaNone is not supported in CGBitmapContextCreate. 64 | // Since the original image here has no alpha info, use kCGImageAlphaNoneSkipLast 65 | // to create bitmap graphics contexts without alpha info. 66 | CGContextRef context = CGBitmapContextCreate(NULL, 67 | width, 68 | height, 69 | bitsPerComponent, 70 | bytesPerRow, 71 | colorspaceRef, 72 | kCGBitmapByteOrderDefault|kCGImageAlphaNoneSkipLast); 73 | 74 | // Draw the image into the context and retrieve the new bitmap image without alpha 75 | CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef); 76 | CGImageRef imageRefWithoutAlpha = CGBitmapContextCreateImage(context); 77 | UIImage *imageWithoutAlpha = [UIImage imageWithCGImage:imageRefWithoutAlpha 78 | scale:image.scale 79 | orientation:image.imageOrientation]; 80 | 81 | if (unsupportedColorSpace) { 82 | CGColorSpaceRelease(colorspaceRef); 83 | } 84 | 85 | CGContextRelease(context); 86 | CGImageRelease(imageRefWithoutAlpha); 87 | 88 | return imageWithoutAlpha; 89 | } 90 | } 91 | 92 | @end 93 | -------------------------------------------------------------------------------- /Classes/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 | -------------------------------------------------------------------------------- /Classes/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 | -------------------------------------------------------------------------------- /Classes/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 | -------------------------------------------------------------------------------- /Classes/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 | -------------------------------------------------------------------------------- /Classes/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 | -------------------------------------------------------------------------------- /Classes/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 | -------------------------------------------------------------------------------- /Classes/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 | -------------------------------------------------------------------------------- /Classes/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 | -------------------------------------------------------------------------------- /Classes/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 | -------------------------------------------------------------------------------- /Classes/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 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/CollectionViewInfo/MFlowLayOut.h: -------------------------------------------------------------------------------- 1 | // 2 | // MFlowLayOut.h 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/10. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MFlowLayOut : UICollectionViewFlowLayout 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/CollectionViewInfo/MFlowLayOut.m: -------------------------------------------------------------------------------- 1 | // 2 | // MFlowLayOut.m 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/10. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 8 | 9 | #import "MFlowLayOut.h" 10 | #import "MHeaderImaCell.h" 11 | @implementation MFlowLayOut 12 | 13 | /* 14 | // Only override drawRect: if you perform custom drawing. 15 | // An empty implementation adversely affects performance during animation. 16 | - (void)drawRect:(CGRect)rect { 17 | // Drawing code 18 | } 19 | */ 20 | - (NSArray *) layoutAttributesForElementsInRect:(CGRect)rect { 21 | 22 | 23 | NSArray *arr = [super layoutAttributesForElementsInRect:rect]; 24 | 25 | 26 | for (UICollectionViewLayoutAttributes *att in arr) { 27 | if (att.representedElementCategory == UICollectionElementCategoryCell) { 28 | MHeaderImaCell *cell = (MHeaderImaCell *)[self.collectionView cellForItemAtIndexPath:att.indexPath]; 29 | 30 | float offSet_x = fabs(self.collectionView.contentOffset.x - (att.frame.origin.x - CGRectGetWidth(self.collectionView.frame))); 31 | CGRect cellRect = cell.btnCheckMark.frame; 32 | cellRect.origin.x = MIN(offSet_x>MHeaderImaCellBtn_width?offSet_x-MHeaderImaCellBtn_width:0, fabs(CGRectGetWidth(att.frame) - CGRectGetWidth(cell.btnCheckMark.frame))); 33 | cell.btnCheckMark.frame = cellRect; 34 | 35 | } 36 | } 37 | 38 | return arr; 39 | } 40 | 41 | - (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds { 42 | 43 | return YES; 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/CollectionViewInfo/MHeadImaView.h: -------------------------------------------------------------------------------- 1 | // 2 | // MHeadImaView.h 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/10. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 仿QQ照片选择器 8 | 9 | #import 10 | 11 | typedef enum { 12 | 13 | headImaCheckMark = 1, 14 | headImaSelectBig = 2, 15 | headImaCheckCancel = 3 16 | 17 | }headImaSelectType; 18 | 19 | @protocol MHeadImaViewDelegate 20 | 21 | - (void)selectIndex:(NSUInteger)index headImaSelectType:(headImaSelectType)type; 22 | 23 | @end 24 | 25 | @interface MHeadImaView : UIView 26 | 27 | @property (nonatomic, weak) id delegate; 28 | - (void)reloadDataWithArr:(NSArray *)arrData arrSelected:(NSMutableArray *)arrSelected; 29 | @end 30 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/CollectionViewInfo/MHeadImaView.m: -------------------------------------------------------------------------------- 1 | // 2 | // MHeadImaView.m 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/10. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 8 | 9 | #import "MHeadImaView.h" 10 | #import "MFlowLayOut.h" 11 | #import "MHeaderImaCell.h" 12 | #import "MImaLibTool.h" 13 | #import 14 | @interface MHeadImaView () 15 | @property (nonatomic, strong) UICollectionView *collectionView; 16 | @property (nonatomic,strong) NSArray *arrData; 17 | @property (nonatomic, strong) NSMutableArray *arrSelected; 18 | @end 19 | 20 | @implementation MHeadImaView 21 | 22 | - (instancetype)initWithFrame:(CGRect)frame { 23 | 24 | if (self = [super initWithFrame:frame]) { 25 | 26 | MFlowLayOut *flowLayout = [[MFlowLayOut alloc] init]; 27 | flowLayout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5); 28 | flowLayout.minimumInteritemSpacing = 5; 29 | flowLayout.minimumLineSpacing = 5; 30 | flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal; 31 | 32 | self.collectionView = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:flowLayout]; 33 | self.collectionView.backgroundColor = [UIColor whiteColor]; 34 | self.collectionView.delegate = self; 35 | self.collectionView.dataSource = self; 36 | self.collectionView.showsHorizontalScrollIndicator = NO; 37 | self.collectionView.showsVerticalScrollIndicator = NO; 38 | [self addSubview:self.collectionView]; 39 | [self.collectionView registerClass:[MHeaderImaCell class] forCellWithReuseIdentifier:MHeaderImaCellClassName]; 40 | 41 | } 42 | return self; 43 | } 44 | 45 | - (void)reloadDataWithArr:(NSArray *)arrData arrSelected:(NSMutableArray *)arrSelected{ 46 | 47 | self.arrSelected = arrSelected; 48 | self.arrData = arrData; 49 | [self.collectionView.collectionViewLayout invalidateLayout]; 50 | [self.collectionView reloadData]; 51 | 52 | 53 | } 54 | 55 | - (CGSize)getImaSizeWithAsset:(ALAsset *)set { 56 | 57 | CGSize imaSize ; 58 | ALAssetRepresentation *sentation = [set defaultRepresentation]; 59 | float scale = sentation.dimensions.width/sentation.dimensions.height; 60 | imaSize.width = floor(180*scale); 61 | imaSize.height = 180; 62 | return imaSize; 63 | } 64 | 65 | #pragma mark - collectionViewDatasourceAndDelegate 66 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { 67 | 68 | return self.arrData.count; 69 | } 70 | 71 | - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 72 | 73 | MHeaderImaCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:MHeaderImaCellClassName forIndexPath:indexPath]; 74 | cell.backgroundColor = [UIColor grayColor]; 75 | ALAsset *set = self.arrData[indexPath.row]; 76 | ALAssetRepresentation *sentation = [set defaultRepresentation]; 77 | cell.imavHead.image = [UIImage imageWithCGImage:[sentation fullScreenImage]]; 78 | cell.btnCheckMark.selected = [[MImaLibTool shareMImaLibTool] imaInArrImasWithArr:self.arrSelected set:set]; 79 | __weak typeof(self) weakSelf = self; 80 | [cell setBtnSelectedActionBlock:^(BOOL state) { 81 | 82 | if (state) { 83 | [weakSelf.arrSelected addObject:set]; 84 | } else { 85 | [weakSelf.arrSelected removeObject:set]; 86 | } 87 | if ([weakSelf.delegate respondsToSelector:@selector(selectIndex:headImaSelectType:)]) { 88 | [weakSelf.delegate selectIndex:indexPath.row headImaSelectType:(state)?headImaCheckMark:headImaCheckCancel]; 89 | } 90 | 91 | }]; 92 | return cell; 93 | } 94 | 95 | 96 | - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { 97 | if ([self.delegate respondsToSelector:@selector(selectIndex:headImaSelectType:)]) { 98 | [self.delegate selectIndex:indexPath.row headImaSelectType:headImaSelectBig]; 99 | } 100 | 101 | } 102 | 103 | - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { 104 | 105 | if (self.arrData.count > 0) { 106 | return [self getImaSizeWithAsset:self.arrData[indexPath.row]]; 107 | } 108 | 109 | return CGSizeZero; 110 | 111 | } 112 | 113 | /* 114 | // Only override drawRect: if you perform custom drawing. 115 | // An empty implementation adversely affects performance during animation. 116 | - (void)drawRect:(CGRect)rect { 117 | // Drawing code 118 | } 119 | */ 120 | 121 | @end 122 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/CollectionViewInfo/MHeaderImaCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // MHeaderImaCell.h 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/10. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "ImagePickerDefine.h" 11 | static NSString *const MHeaderImaCellClassName = @"MHeaderImaCell"; 12 | static float MHeaderImaCellBtn_x_space = 5; 13 | static float MHeaderImaCellBtn_width = 40; 14 | @interface MHeaderImaCell : UICollectionViewCell 15 | @property (nonatomic, strong) UIButton *btnCheckMark; 16 | @property (nonatomic, strong) UIImageView *imavHead; 17 | - (void)setBtnSelectedActionBlock:(MBoolBlock)block; 18 | @end 19 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/CollectionViewInfo/MHeaderImaCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // MHeaderImaCell.m 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/10. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 8 | 9 | #import "MHeaderImaCell.h" 10 | 11 | @implementation MHeaderImaCell 12 | { 13 | 14 | MBoolBlock _actionBlock; 15 | } 16 | - (instancetype)initWithFrame:(CGRect)frame { 17 | 18 | if (self = [super initWithFrame:frame]) { 19 | 20 | 21 | self.clipsToBounds = YES; 22 | self.imavHead = [[UIImageView alloc] initWithFrame:self.bounds]; 23 | self.imavHead.clipsToBounds = YES; 24 | [self addSubview:self.imavHead]; 25 | 26 | self.btnCheckMark = [UIButton buttonWithType:UIButtonTypeCustom]; 27 | self.btnCheckMark.frame = CGRectMake(CGRectGetWidth(self.frame)-MHeaderImaCellBtn_width, 0, MHeaderImaCellBtn_width, MHeaderImaCellBtn_width); 28 | [self.btnCheckMark addTarget:self action:@selector(actionBtn:) forControlEvents:UIControlEventTouchUpInside]; 29 | [self addSubview:self.btnCheckMark]; 30 | 31 | [self.btnCheckMark setImage:[UIImage imageNamed:@"ico_check_select@2x.png"] forState:UIControlStateSelected]; 32 | [self.btnCheckMark setImage:[UIImage imageNamed:@"ico_check_nomal@2x.png"] forState:UIControlStateNormal]; 33 | } 34 | return self; 35 | } 36 | 37 | - (void)actionBtn:(UIButton *)btn { 38 | 39 | btn.selected = !btn.selected; 40 | (!_actionBlock)?:_actionBlock(btn.selected); 41 | } 42 | 43 | - (void)setBtnSelectedActionBlock:(MBoolBlock)block { 44 | 45 | _actionBlock = block; 46 | } 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/JJPhotoViewer/JJMainScrollView.h: -------------------------------------------------------------------------------- 1 | // 2 | // JJMainScrollView.h 3 | // test 4 | // 5 | // Created by KimBox on 15/4/28. 6 | // Copyright (c) 2015年 KimBox. All rights reserved. 7 | // 8 | 9 | 10 | typedef enum { 11 | JJLocalWithLocalPhotoViewer, //点击前是本地图,点击后也是本地图 12 | JJInternetWithInternetPhotoViewer //点击前是网络图,点击后也是网络图 13 | }JJPhotoViewerType; 14 | 15 | #import 16 | 17 | 18 | 19 | @protocol JJPhotoDelegate 20 | 21 | @optional 22 | //关闭PhotoViewer时调用并返回 (观看的最后一张图片的序号) 23 | -(void)photoViwerWilldealloc:(NSInteger)selecedImageViewIndex; 24 | @end 25 | 26 | 27 | @interface JJMainScrollView : UIScrollView 28 | 29 | 30 | //获取数据 31 | -(void)setPhotoData:(NSArray *)photoArr Type:(JJPhotoViewerType)type; 32 | 33 | /**代理*/ 34 | @property(nonatomic,weak)id mainDelegate; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/JJPhotoViewer/JJOneScrollView.h: -------------------------------------------------------------------------------- 1 | // 2 | // JJOneScrollView.h 3 | // test 4 | // 5 | // Created by KimBox on 15/5/4. 6 | // Copyright (c) 2015年 KimBox. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol JJOneScrollViewDelegate 12 | 13 | -(void)goBack; 14 | 15 | -(void)willGoBack:(NSInteger)seletedIndex; 16 | 17 | @optional 18 | 19 | @end 20 | @interface JJOneScrollView : UIScrollView 21 | 22 | 23 | //代理 24 | @property(nonatomic,weak)id mydelegate; 25 | 26 | /**浏览器中我是第几个图片?*/ 27 | @property(nonatomic,assign)NSInteger myindex; 28 | 29 | 30 | 31 | //❤️本地加载图 32 | -(void)setLocalImage:(UIImageView *)imageView ; 33 | 34 | //❤️网络加载图 35 | -(void)setNetWorkImage:(UIImageView *)imageView urlStr:(NSString *)urlStr ; 36 | 37 | 38 | //回复放大缩小前的原状 39 | -(void)reloadFrame; 40 | 41 | 42 | 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/JJPhotoViewer/JJPhoto.h: -------------------------------------------------------------------------------- 1 | // 2 | // JJPhoto.h 3 | // test 4 | // 5 | // Created by KimBox on 15/4/28. 6 | // Copyright (c) 2015年 KimBox. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface JJPhoto : NSObject 13 | 14 | /**点进来的小图片ImageView*/ 15 | @property(nonatomic,strong)UIImageView *imageView; 16 | 17 | /**要显示的网络地址*/ 18 | @property(nonatomic,copy)NSString *urlStr; 19 | 20 | /**holdimage*/ 21 | @property(nonatomic,assign)CGRect oldRect; 22 | 23 | /**是不是点进来的那个ImageView*/ 24 | @property(nonatomic,assign)BOOL isSelecImageView; 25 | 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/JJPhotoViewer/JJPhoto.m: -------------------------------------------------------------------------------- 1 | // 2 | // JJPhoto.m 3 | // test 4 | // 5 | // Created by KimBox on 15/4/28. 6 | // Copyright (c) 2015年 KimBox. All rights reserved. 7 | // 8 | 9 | #import "JJPhoto.h" 10 | 11 | @implementation JJPhoto 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/JJPhotoViewer/JJPhotoManeger.h: -------------------------------------------------------------------------------- 1 | // 2 | // JJPhotoManeger.h 3 | // test 4 | // 5 | // Created by KimBox on 15/4/28. 6 | // Copyright (c) 2015年 KimBox. All rights reserved. 7 | // 8 | 9 | 10 | 11 | 12 | #import 13 | #import 14 | //view 15 | #import "JJMainScrollView.h" 16 | 17 | 18 | @interface JJPhotoManeger : NSObject 19 | /** 20 | * 创建 21 | */ 22 | +(instancetype)maneger; 23 | 24 | /** 25 | 代理 26 | */ 27 | @property(nonatomic,weak)id delegate; 28 | 29 | 30 | 31 | 32 | #pragma mark - ❤️俩核心功能 33 | 34 | /** 35 | * 本地图片放大浏览 36 | */ 37 | -(void)showLocalPhotoViewer:(NSArray *)imageViews selecImageindex:(NSInteger)selecImageindex; 38 | 39 | 40 | /** 41 | * 放大浏览网络图片 42 | */ 43 | -(void)showNetworkPhotoViewer:(NSArray *)imageViews urlStrArr:(NSArray *)urlStrArr selecImageindex:(NSInteger)selecImageindex; 44 | 45 | 46 | 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/JJPhotoViewer/JJPhotoManeger.m: -------------------------------------------------------------------------------- 1 | // 2 | // JJPhotoManeger.m 3 | // test 4 | // 5 | // Created by KimBox on 15/4/28. 6 | // Copyright (c) 2015年 KimBox. All rights reserved. 7 | // 8 | 9 | #import "JJPhotoManeger.h" 10 | //model 11 | #import "JJPhoto.h" 12 | 13 | 14 | @implementation JJPhotoManeger 15 | 16 | /** 17 | * 创建 18 | */ 19 | +(instancetype)maneger 20 | { 21 | JJPhotoManeger *mg = [[JJPhotoManeger alloc]init]; 22 | return mg; 23 | } 24 | 25 | 26 | /** 27 | * 本地图片放大浏览 28 | */ 29 | -(void)showLocalPhotoViewer:(NSArray *)imageViews selecImageindex:(NSInteger)selecImageindex 30 | { 31 | [self setUpPhotoData:imageViews selecImageindex:selecImageindex urlStrArr:nil type:JJLocalWithLocalPhotoViewer]; 32 | } 33 | 34 | 35 | /** 36 | * 点击网络下载图片浏览 37 | */ 38 | -(void)showNetworkPhotoViewer:(NSArray *)imageViews urlStrArr:(NSArray *)urlStrArr selecImageindex:(NSInteger)selecImageindex 39 | { 40 | 41 | [self setUpPhotoData:imageViews selecImageindex:selecImageindex urlStrArr:urlStrArr type:JJInternetWithInternetPhotoViewer]; 42 | } 43 | 44 | 45 | 46 | //拿到数据设置整体页面 47 | -(void)setUpPhotoData:(NSArray *)imageViews selecImageindex:(NSInteger)selecImageindex urlStrArr:(NSArray *)urlStrArr type:(JJPhotoViewerType)type 48 | { 49 | 50 | 51 | //创建模型数组 52 | NSMutableArray *photoModelArr = [NSMutableArray array]; 53 | 54 | 55 | for (int i = 0; i < imageViews.count; i ++) { 56 | 57 | //创建模型 58 | JJPhoto *photo = [[JJPhoto alloc]init]; 59 | 60 | //取出imageView 61 | UIImageView *imageView = imageViews[i]; 62 | 63 | //包装模型 64 | photo.imageView = imageView; 65 | 66 | //如果是网络看图模式 67 | if(type == JJInternetWithInternetPhotoViewer) 68 | { 69 | //包装网络地址 70 | if(i >= urlStrArr.count || urlStrArr == nil ) 71 | { 72 | photo.urlStr = @""; 73 | }else 74 | { 75 | photo.urlStr = urlStrArr[i]; 76 | } 77 | } 78 | 79 | //包装信息:这个imageView是不是点击进来的时候的imageView 80 | if(i == (int)selecImageindex){ 81 | photo.isSelecImageView = YES; 82 | }else{ 83 | photo.isSelecImageView = NO; 84 | } 85 | 86 | //放入模型数组 87 | [photoModelArr addObject:photo]; 88 | } 89 | 90 | //传模型包给主滚动窗 91 | JJMainScrollView *mainScrollView = [[JJMainScrollView alloc]init]; 92 | //传递代理 93 | mainScrollView.mainDelegate = self.delegate; 94 | //给数据 type:然后说明是本地加载/还是网络加载 95 | [mainScrollView setPhotoData:photoModelArr Type:type]; 96 | //展示 97 | [self show:mainScrollView]; 98 | 99 | } 100 | 101 | 102 | //展示 103 | -(void)show:(UIScrollView *)mainScrollView 104 | { 105 | //创建原始的底层View一个 106 | UIView *view = [[UIView alloc]init]; 107 | view.frame = [UIApplication sharedApplication].keyWindow.rootViewController.view.bounds; 108 | [view addSubview:mainScrollView]; 109 | // [[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:view]; 110 | 111 | UIWindow *window = [[UIApplication sharedApplication] keyWindow]; 112 | NSArray *windowViews = [window subviews]; 113 | if(windowViews && [windowViews count] > 0){ 114 | UIView *subView = [windowViews objectAtIndex:[windowViews count]-1]; 115 | for(UIView *aSubView in subView.subviews) 116 | { 117 | [aSubView.layer removeAllAnimations]; 118 | } 119 | [subView addSubview:view]; 120 | } 121 | } 122 | 123 | 124 | 125 | 126 | 127 | @end 128 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/JJPhotoViewer/none.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qxuewei/XWPublish/15f107959ec45c7e9f5a30479f4f21947b069de9/Classes/XWPublish/XWImagePicker/Lib/JJPhotoViewer/none.png -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/MImgpicker/ImagePickerDefine.h: -------------------------------------------------------------------------------- 1 | // 2 | // Define.h 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/11. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 8 | 9 | #ifndef QQImagePicker_Define_h 10 | #define QQImagePicker_Define_h 11 | 12 | typedef void (^MBasicBlock)(); 13 | typedef void (^MIndexBlock)(int index); 14 | typedef void (^MobjBlock)(id obj); 15 | typedef void (^MBoolBlock)(BOOL state); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/MImgpicker/MGroupCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGroupCell.h 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/11. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | static NSString *const MGroupCellClassName = @"MGroupCell"; 12 | @interface MGroupCell : UITableViewCell 13 | @property (weak, nonatomic) IBOutlet UIImageView *imavHead; 14 | @property (weak, nonatomic) IBOutlet UILabel *lblInfo; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/MImgpicker/MGroupCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // MGroupCell.m 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/11. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 8 | 9 | #import "MGroupCell.h" 10 | 11 | @implementation MGroupCell 12 | 13 | - (void)awakeFromNib { 14 | // Initialization code 15 | // self.lblInfo.textColor = [UIColor colorWithRed:51 green:51 blue:51 alpha:1]; 16 | 17 | if([[[UIDevice currentDevice] systemVersion] floatValue] > 8.0){ 18 | self.layoutMargins = UIEdgeInsetsZero; 19 | self.preservesSuperviewLayoutMargins = NO; 20 | } 21 | self.separatorInset = UIEdgeInsetsMake(0, 60, 0, 0); 22 | self.clipsToBounds = YES; 23 | self.selectionStyle = UITableViewCellSelectionStyleNone; 24 | } 25 | 26 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated { 27 | [super setSelected:selected animated:animated]; 28 | 29 | // Configure the view for the selected state 30 | } 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/MImgpicker/MGroupCell.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/MImgpicker/MImaCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // MImaCell.h 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/11. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "ImagePickerDefine.h" 11 | 12 | @protocol MImaCellDelegate 13 | 14 | - (BOOL)arrayIsfulled; 15 | 16 | @end 17 | 18 | static NSString *MImaCellClassName = @"MImaCell"; 19 | 20 | @interface MImaCell : UICollectionViewCell 21 | 22 | @property(nonatomic,assign) id delegate; 23 | 24 | @property (weak, nonatomic) IBOutlet UIImageView *imavHead; 25 | @property (weak, nonatomic) IBOutlet UIButton *btnCheckMark; 26 | 27 | 28 | @property(nonatomic,strong) UIImageView *BigImgView; 29 | 30 | - (void)setBtnSelectedHandle:(MBoolBlock)block; 31 | 32 | - (void)setBigImgViewWithImage:(UIImage *)img; 33 | @end 34 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/MImgpicker/MImaCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // MImaCell.m 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/11. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 8 | 9 | #import "MImaCell.h" 10 | 11 | @implementation MImaCell 12 | { 13 | 14 | MBoolBlock _boolBlock; 15 | } 16 | - (void)awakeFromNib { 17 | // Initialization code 18 | [self.btnCheckMark setImage:[UIImage imageNamed:@"ico_check_select@2x.png"] forState:UIControlStateSelected]; 19 | } 20 | 21 | - (void)setBtnSelectedHandle:(MBoolBlock)block { 22 | 23 | _boolBlock = block; 24 | } 25 | 26 | - (IBAction)actionBtn:(id)sender { 27 | if ([self.delegate arrayIsfulled] && !self.btnCheckMark.selected) { 28 | return; 29 | } 30 | self.btnCheckMark.selected = !self.btnCheckMark.selected; 31 | (!_boolBlock) ?: _boolBlock(self.btnCheckMark.selected); 32 | } 33 | 34 | - (void)setBigImgViewWithImage:(UIImage *)img{ 35 | if (_BigImgView) { 36 | return; 37 | } 38 | _BigImgView = [[UIImageView alloc]initWithImage:img]; 39 | _BigImgView.frame = _imavHead.frame; 40 | [self insertSubview:_BigImgView atIndex:0]; 41 | } 42 | @end 43 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/MImgpicker/MImaCell.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/MImgpicker/MImaLibTool.h: -------------------------------------------------------------------------------- 1 | // 2 | // MImaLibTool.h 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/11. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | typedef void (^arrBlock)(NSArray *arrObj); 13 | @interface MImaLibTool : NSObject 14 | + (id)shareMImaLibTool; 15 | 16 | 17 | - (void)getAllGroupWithArrObj:(arrBlock)block; 18 | - (NSArray *)getAllAssetsWithGroup:(ALAssetsGroup *)group; 19 | //- (void)getAllAssetsWithGroup:(ALAssetsGroup *)group finishBlock:(arrBlock)block; 20 | 21 | - (BOOL)imaInArrImasWithArr:(NSArray *)arrIma set:(ALAsset *)set; 22 | - (NSArray *)checkMarkSameSetWithArr:(NSArray *)arrSelected set:(ALAsset *)set; 23 | 24 | @property (nonatomic, strong) ALAssetsLibrary *lib; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/MImgpicker/MImaLibTool.m: -------------------------------------------------------------------------------- 1 | // 2 | // MImaLibTool.m 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/11. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 8 | 9 | #import "MImaLibTool.h" 10 | 11 | @interface MImaLibTool () 12 | 13 | @end 14 | 15 | @implementation MImaLibTool 16 | 17 | + (id)shareMImaLibTool { 18 | 19 | static MImaLibTool *tool; 20 | static dispatch_once_t once; 21 | dispatch_once(&once, ^{ 22 | 23 | tool = [[[self class] alloc] init]; 24 | tool.lib = [[ALAssetsLibrary alloc] init]; 25 | }); 26 | 27 | return tool; 28 | } 29 | 30 | 31 | 32 | - (NSArray *)checkMarkSameSetWithArr:(NSArray *)arrSelected set:(ALAsset *)set { 33 | NSString *urlstring = set.defaultRepresentation.url.absoluteString; 34 | NSPredicate *pre = [NSPredicate predicateWithFormat:@"SELF.defaultRepresentation.url.absoluteString == %@",urlstring]; 35 | NSArray *arr = [arrSelected filteredArrayUsingPredicate:pre]; 36 | return arr; 37 | } 38 | 39 | - (BOOL)imaInArrImasWithArr:(NSArray *)arrIma set:(ALAsset *)set { 40 | 41 | // NSString *uti = set.defaultRepresentation.UTI; 42 | // NSString *UTI = [[[arrIma lastObject] defaultRepresentation] UTI]; 43 | return [self checkMarkSameSetWithArr:arrIma set:set].count > 0; 44 | } 45 | 46 | - (void)getAllGroupWithArrObj:(arrBlock)block { 47 | 48 | 49 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 50 | 51 | NSMutableArray *arrGroup = [NSMutableArray array]; 52 | [_lib enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) { 53 | 54 | if (group) { 55 | [arrGroup addObject:group]; 56 | } else { 57 | dispatch_async(dispatch_get_main_queue(), ^{ 58 | if (arrGroup.count > 0) { 59 | (!block)?:block([arrGroup copy]); 60 | } 61 | }); 62 | } 63 | 64 | 65 | } failureBlock:^(NSError *error) { 66 | 67 | }]; 68 | 69 | 70 | }); 71 | 72 | } 73 | 74 | - (NSArray *)getAllAssetsWithGroup:(ALAssetsGroup *)group { 75 | 76 | NSMutableArray *arr = [NSMutableArray array]; 77 | 78 | [group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { 79 | if (result) { 80 | [arr addObject:result]; 81 | } 82 | }]; 83 | return [arr copy]; 84 | } 85 | 86 | 87 | @end 88 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/MImgpicker/MShowAllGroup.h: -------------------------------------------------------------------------------- 1 | // 2 | // MShowAllGroup.h 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/11. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MShowGroupAllSet.h" 11 | 12 | @protocol MShowAllGroupDelegate 13 | -(void)finishSelectImg; 14 | @end 15 | 16 | @interface MShowAllGroup : UIViewController 17 | 18 | @property(nonatomic,assign) id delegate; 19 | 20 | - (id)initWithArrGroup:(NSArray *)arrGroup arrSelected:(NSMutableArray *)arrSelected; 21 | @property (nonatomic, strong) NSMutableArray *arrSeleted; 22 | 23 | @property(nonatomic,strong) MShowGroupAllSet *mvc; 24 | 25 | //图片总数量限制 26 | @property(nonatomic,assign)NSInteger maxCout; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/MImgpicker/MShowAllGroup.m: -------------------------------------------------------------------------------- 1 | // 2 | // MShowAllGroup.m 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/11. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 8 | 9 | #import "MShowAllGroup.h" 10 | #import "MGroupCell.h" 11 | #import 12 | #import "MImaLibTool.h" 13 | 14 | @interface MShowAllGroup () 15 | 16 | @property (nonatomic, strong) NSArray *arrGroup; 17 | @property (nonatomic, strong) UITableView *tableView; 18 | 19 | 20 | @end 21 | 22 | @implementation MShowAllGroup 23 | 24 | - (id)initWithArrGroup:(NSArray *)arrGroup arrSelected:(NSMutableArray *)arr { 25 | 26 | if (self = [super init]) { 27 | 28 | self.arrSeleted = arr; 29 | self.arrGroup = arrGroup; 30 | } 31 | return self; 32 | } 33 | 34 | - (void)viewDidLoad { 35 | [super viewDidLoad]; 36 | self.title = @"照片"; 37 | self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds]; 38 | self.tableView.delegate = self; 39 | self.tableView.dataSource = self; 40 | self.tableView.tableFooterView = [UIView new]; 41 | self.tableView.rowHeight = 50; 42 | [self.view addSubview:self.tableView]; 43 | 44 | [self.tableView registerNib:[UINib nibWithNibName:MGroupCellClassName bundle:nil] forCellReuseIdentifier:MGroupCellClassName]; 45 | 46 | UIBarButtonItem *rightBar = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(actionRightBar)]; 47 | self.navigationItem.rightBarButtonItem = rightBar; 48 | // Do any additional setup after loading the view. 49 | } 50 | 51 | 52 | - (void)actionRightBar { 53 | 54 | [self.navigationController dismissViewControllerAnimated:YES completion:nil]; 55 | } 56 | 57 | #pragma mark - tableDelegate 58 | 59 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 60 | 61 | return self.arrGroup.count; 62 | } 63 | 64 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 65 | 66 | MGroupCell *cell = [tableView dequeueReusableCellWithIdentifier:MGroupCellClassName]; 67 | ALAssetsGroup *froup = self.arrGroup[indexPath.row]; 68 | cell.lblInfo.text = [NSString stringWithFormat:@"%@(%ld)",[froup valueForProperty:ALAssetsGroupPropertyName],[froup numberOfAssets]]; 69 | cell.imavHead.image = [UIImage imageWithCGImage:froup.posterImage]; 70 | return cell; 71 | } 72 | 73 | 74 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 75 | 76 | // if (!_mvc) { 77 | // _mvc = [[MShowGroupAllSet alloc] initWithGroup:self.arrGroup[indexPath.row] selectedArr:self.arrSeleted]; 78 | // _mvc.delegate = self; 79 | // } 80 | // else{ 81 | // _mvc.arrSelected = _arrSeleted; 82 | // } 83 | 84 | _mvc = [[MShowGroupAllSet alloc] initWithGroup:self.arrGroup[indexPath.row] selectedArr:self.arrSeleted]; 85 | _mvc.delegate = self; 86 | _mvc.arrSelected = _arrSeleted; 87 | 88 | 89 | _mvc.MaxCount = _maxCout; 90 | [self.navigationController pushViewController:_mvc animated:YES]; 91 | } 92 | 93 | - (void)didReceiveMemoryWarning { 94 | [super didReceiveMemoryWarning]; 95 | } 96 | 97 | - (void)finishSelectImg{ 98 | [self.delegate finishSelectImg]; 99 | } 100 | 101 | @end 102 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/MImgpicker/MShowGroupAllSet.h: -------------------------------------------------------------------------------- 1 | // 2 | // MShowGroupAllSet.h 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/11. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import "JJPhotoManeger.h" 12 | @protocol MShowGroupAllSetDelegate 13 | -(void)finishSelectImg; 14 | @end 15 | 16 | @interface MShowGroupAllSet : UIViewController 17 | - (id)initWithGroup:(ALAssetsGroup *)group selectedArr:(NSMutableArray *)arrSelected; 18 | 19 | @property(nonatomic,assign)NSInteger MaxCount; 20 | @property(nonatomic,assign) id delegate; 21 | @property (nonatomic, strong) NSMutableArray *arrSelected; 22 | 23 | @property(nonatomic,strong) NSMutableArray *imgViewArray; 24 | @end 25 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/SDProgressView/Lib/SDBaseProgressView.h: -------------------------------------------------------------------------------- 1 | // 2 | // SDBaseProgressView.h 3 | // SDProgressView 4 | // 5 | // Created by aier on 15-2-19. 6 | // Copyright (c) 2015年 GSD. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #define SDColorMaker(r, g, b, a) [UIColor colorWithRed:((r) / 255.0) green:((g) / 255.0) blue:((b) / 255.0) alpha:(a)] 12 | 13 | #define SDProgressViewItemMargin 10 14 | 15 | #define SDProgressViewFontScale (MIN(self.frame.size.width, self.frame.size.height) / 100.0) 16 | 17 | // 背景颜色 18 | #define SDProgressViewBackgroundColor SDColorMaker(240, 240, 240, 0.9) 19 | 20 | @interface SDBaseProgressView : UIView 21 | 22 | @property (nonatomic, assign) CGFloat progress; 23 | 24 | - (void)setCenterProgressText:(NSString *)text withAttributes:(NSDictionary *)attributes; 25 | 26 | - (void)dismiss; 27 | 28 | + (id)progressView; 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/SDProgressView/Lib/SDBaseProgressView.m: -------------------------------------------------------------------------------- 1 | // 2 | // SDBaseProgressView.m 3 | // SDProgressView 4 | // 5 | // Created by aier on 15-2-19. 6 | // Copyright (c) 2015年 GSD. All rights reserved. 7 | // 8 | 9 | #import "SDBaseProgressView.h" 10 | 11 | @implementation SDBaseProgressView 12 | 13 | - (id)initWithFrame:(CGRect)frame 14 | { 15 | if (self = [super initWithFrame:frame]) { 16 | // self.backgroundColor = SDProgressViewBackgroundColor; 17 | self.backgroundColor = [UIColor clearColor]; 18 | self.layer.cornerRadius = 5; 19 | self.clipsToBounds = YES; 20 | } 21 | return self; 22 | } 23 | 24 | - (void)setProgress:(CGFloat)progress 25 | { 26 | _progress = progress; 27 | 28 | if (progress >= 1.0) { 29 | [self removeFromSuperview]; 30 | } else { 31 | [self setNeedsDisplay]; 32 | } 33 | 34 | } 35 | 36 | - (void)setCenterProgressText:(NSString *)text withAttributes:(NSDictionary *)attributes 37 | { 38 | CGFloat xCenter = self.frame.size.width * 0.5; 39 | CGFloat yCenter = self.frame.size.height * 0.5; 40 | 41 | // 判断系统版本 42 | if ([[UIDevice currentDevice].systemVersion floatValue] >= 7.0) { 43 | CGSize strSize = [text sizeWithAttributes:attributes]; 44 | CGFloat strX = xCenter - strSize.width * 0.5; 45 | CGFloat strY = yCenter - strSize.height * 0.5; 46 | [text drawAtPoint:CGPointMake(strX, strY) withAttributes:attributes]; 47 | } else { 48 | CGSize strSize; 49 | NSAttributedString *attrStr = nil; 50 | if (attributes[NSFontAttributeName]) { 51 | strSize = [text sizeWithFont:attributes[NSFontAttributeName]]; 52 | attrStr = [[NSAttributedString alloc] initWithString:text attributes:attributes]; 53 | } else { 54 | strSize = [text sizeWithFont:[UIFont systemFontOfSize:[UIFont systemFontSize]]]; 55 | attrStr = [[NSAttributedString alloc] initWithString:text attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:[UIFont systemFontSize]]}]; 56 | } 57 | 58 | CGFloat strX = xCenter - strSize.width * 0.5; 59 | CGFloat strY = yCenter - strSize.height * 0.5; 60 | 61 | [attrStr drawAtPoint:CGPointMake(strX, strY)]; 62 | } 63 | 64 | } 65 | 66 | // 清除指示器 67 | - (void)dismiss 68 | { 69 | self.progress = 1.0; 70 | } 71 | 72 | + (id)progressView 73 | { 74 | return [[self alloc] init]; 75 | } 76 | 77 | @end 78 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/SDProgressView/Lib/SDLoopProgressView.h: -------------------------------------------------------------------------------- 1 | // 2 | // SDLoopProgressView.h 3 | // SDProgressView 4 | // 5 | // Created by aier on 15-2-19. 6 | // Copyright (c) 2015年 GSD. All rights reserved. 7 | // 8 | 9 | #import "SDBaseProgressView.h" 10 | 11 | @interface SDLoopProgressView : SDBaseProgressView 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/SDProgressView/Lib/SDLoopProgressView.m: -------------------------------------------------------------------------------- 1 | // 2 | // SDLoopProgressView.m 3 | // SDProgressView 4 | // 5 | // Created by aier on 15-2-19. 6 | // Copyright (c) 2015年 GSD. All rights reserved. 7 | // 8 | 9 | #import "SDLoopProgressView.h" 10 | 11 | @implementation SDLoopProgressView 12 | 13 | - (void)drawRect:(CGRect)rect 14 | { 15 | CGContextRef ctx = UIGraphicsGetCurrentContext(); 16 | 17 | CGFloat xCenter = rect.size.width * 0.5; 18 | CGFloat yCenter = rect.size.height * 0.5; 19 | [[UIColor whiteColor] set]; 20 | 21 | CGContextSetLineWidth(ctx, 15 * SDProgressViewFontScale); 22 | CGContextSetLineCap(ctx, kCGLineCapRound); 23 | CGFloat to = - M_PI * 0.5 + self.progress * M_PI * 2 + 0.05; // 初始值0.05 24 | CGFloat radius = MIN(rect.size.width, rect.size.height) * 0.5 - SDProgressViewItemMargin; 25 | CGContextAddArc(ctx, xCenter, yCenter, radius, - M_PI * 0.5, to, 0); 26 | CGContextStrokePath(ctx); 27 | 28 | // 进度数字 29 | NSString *progressStr = [NSString stringWithFormat:@"%.0f", self.progress * 100]; 30 | NSMutableDictionary *attributes = [NSMutableDictionary dictionary]; 31 | attributes[NSFontAttributeName] = [UIFont boldSystemFontOfSize:20 * SDProgressViewFontScale]; 32 | attributes[NSForegroundColorAttributeName] = [UIColor whiteColor]; 33 | [self setCenterProgressText:progressStr withAttributes:attributes]; 34 | } 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/SDProgressView/Lib/SDProgressView.h: -------------------------------------------------------------------------------- 1 | // 2 | // SDProgressView.h 3 | // SDProgressView 4 | // 5 | // Created by aier on 15-2-21. 6 | // Copyright (c) 2015年 GSD. All rights reserved. 7 | // 8 | 9 | #import "SDLoopProgressView.h" 10 | #import "SDDemoItemView.h" -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/SDProgressView/View/SDDemoItemView.h: -------------------------------------------------------------------------------- 1 | // 2 | // SDDemoItemView.h 3 | // SDProgressView 4 | // 5 | // Created by aier on 15-2-20. 6 | // Copyright (c) 2015年 GSD. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "SDBaseProgressView.h" 11 | 12 | @interface SDDemoItemView : UIView 13 | 14 | @property (nonatomic, assign) Class progressViewClass; 15 | 16 | @property (nonatomic, strong) SDBaseProgressView *progressView; 17 | 18 | + (id)demoItemViewWithClass:(Class)class; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/Lib/SDProgressView/View/SDDemoItemView.m: -------------------------------------------------------------------------------- 1 | // 2 | // SDDemoItemView.m 3 | // SDProgressView 4 | // 5 | // Created by aier on 15-2-20. 6 | // Copyright (c) 2015年 GSD. All rights reserved. 7 | // 8 | 9 | #import "SDDemoItemView.h" 10 | 11 | @implementation SDDemoItemView 12 | 13 | - (id)initWithFrame:(CGRect)frame 14 | { 15 | self = [super initWithFrame:frame]; 16 | if (self) { 17 | } 18 | return self; 19 | } 20 | 21 | - (void)setProgressViewClass:(Class)progressViewClass 22 | { 23 | _progressViewClass = progressViewClass; 24 | self.progressView = [[progressViewClass alloc] init]; 25 | [self addSubview:self.progressView]; 26 | } 27 | 28 | 29 | + (id)demoItemViewWithClass:(Class)class 30 | { 31 | SDDemoItemView *demo = [[self alloc] init]; 32 | demo.progressViewClass = class; 33 | return demo; 34 | } 35 | 36 | - (void)layoutSubviews 37 | { 38 | [super layoutSubviews]; 39 | self.progressView.frame = self.bounds; 40 | } 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/XWImagePickerSheet.h: -------------------------------------------------------------------------------- 1 | // 2 | // XWImagePickerSheet.h 3 | // XWPublishDemo 4 | // 5 | // Created by 邱学伟 on 16/4/15. 6 | // Copyright © 2016年 邱学伟. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import "MHeadImaView.h" 12 | #import "MImaLibTool.h" 13 | #import "MShowAllGroup.h" 14 | 15 | typedef enum { 16 | selectSend = 1, 17 | selectedCancel = 2, 18 | selectedCamera = 3, 19 | selectPhotoLib = 4 20 | }menuSelectedType; 21 | 22 | //定义选择的block方法 23 | typedef void (^menuSelectBlock)(id obj, menuSelectedType type); 24 | 25 | //协议 26 | @protocol XWImagePickerSheetDelegate 27 | 28 | @optional 29 | /** 30 | * 相册完成选择得到图片 31 | */ 32 | -(void)getSelectImageWithALAssetArray:(NSArray *)ALAssetArray thumbnailImageArray:(NSArray *)thumbnailImgArray; 33 | 34 | @end 35 | 36 | @interface XWImagePickerSheet : NSObject{ 37 | UIImagePickerController *imaPic; 38 | UIViewController *viewController; 39 | } 40 | //代理 41 | @property (nonatomic, assign) id delegate; 42 | @property (nonatomic, strong) UITableView *tableview; 43 | @property (nonatomic, strong) NSArray *arrTitles; 44 | @property (nonatomic, copy) menuSelectBlock menuBlock; 45 | @property (nonatomic, strong) NSArray *arrGroup; 46 | @property (nonatomic, strong) NSMutableArray *arrSelected; 47 | @property (nonatomic, assign) NSInteger maxCount; 48 | //显示选择照片提示sheet 49 | -(void)showImgPickerActionSheetInView:(UIViewController *)controller; 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWImagePicker/XWImagePickerSheet.m: -------------------------------------------------------------------------------- 1 | // 2 | // XWImagePickerSheet.m 3 | // XWPublishDemo 4 | // 5 | // Created by 邱学伟 on 16/4/15. 6 | // Copyright © 2016年 邱学伟. All rights reserved. 7 | // 8 | 9 | #import "XWImagePickerSheet.h" 10 | 11 | @interface XWImagePickerSheet () 12 | 13 | @end 14 | 15 | @implementation XWImagePickerSheet 16 | -(instancetype)init{ 17 | self = [super init]; 18 | if (self) { 19 | if (!_arrSelected) { 20 | self.arrSelected = [NSMutableArray array]; 21 | } 22 | } 23 | return self; 24 | } 25 | //显示选择照片提示Sheet 26 | -(void)showImgPickerActionSheetInView:(UIViewController *)controller{ 27 | UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"选择照片" preferredStyle:UIAlertControllerStyleActionSheet]; 28 | UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { 29 | 30 | }]; 31 | UIAlertAction *actionCamera = [UIAlertAction actionWithTitle:[NSString stringWithFormat:@"拍照"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { 32 | if (!imaPic) { 33 | imaPic = [[UIImagePickerController alloc] init]; 34 | } 35 | if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { 36 | imaPic.sourceType = UIImagePickerControllerSourceTypeCamera; 37 | imaPic.delegate = self; 38 | [viewController presentViewController:imaPic animated:NO completion:nil]; 39 | } 40 | 41 | }]; 42 | UIAlertAction *actionAlbum = [UIAlertAction actionWithTitle:[NSString stringWithFormat:@"相册"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { 43 | [self loadImgDataAndShowAllGroup]; 44 | }]; 45 | [alertController addAction:actionCancel]; 46 | [alertController addAction:actionCamera]; 47 | [alertController addAction:actionAlbum]; 48 | viewController = controller; 49 | [viewController presentViewController:alertController animated:YES completion:nil]; 50 | 51 | } 52 | #pragma mark - 加载照片数据 53 | - (void)loadImgDataAndShowAllGroup{ 54 | if (!_arrSelected) { 55 | self.arrSelected = [NSMutableArray array]; 56 | } 57 | [[MImaLibTool shareMImaLibTool] getAllGroupWithArrObj:^(NSArray *arrObj) { 58 | if (arrObj && arrObj.count > 0) { 59 | self.arrGroup = arrObj; 60 | if ( self.arrGroup.count > 0) { 61 | MShowAllGroup *svc = [[MShowAllGroup alloc] initWithArrGroup:self.arrGroup arrSelected:self.arrSelected]; 62 | svc.delegate = self; 63 | UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:svc]; 64 | if (_arrSelected) { 65 | svc.arrSeleted = _arrSelected; 66 | svc.mvc.arrSelected = _arrSelected; 67 | } 68 | svc.maxCout = _maxCount; 69 | [viewController presentViewController:nav animated:YES completion:nil]; 70 | } 71 | } 72 | }]; 73 | } 74 | #pragma mark - 拍照获得数据 75 | -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ 76 | UIImage *theImage = nil; 77 | // 判断,图片是否允许修改 78 | if ([picker allowsEditing]){ 79 | //获取用户编辑之后的图像 80 | theImage = [info objectForKey:UIImagePickerControllerEditedImage]; 81 | } else { 82 | // 照片的元数据参数 83 | theImage = [info objectForKey:UIImagePickerControllerOriginalImage]; 84 | } 85 | if (theImage) { 86 | //保存图片到相册中 87 | MImaLibTool *imgLibTool = [MImaLibTool shareMImaLibTool]; 88 | [imgLibTool.lib writeImageToSavedPhotosAlbum:[theImage CGImage] orientation:(ALAssetOrientation)[theImage imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){ 89 | if (error) { 90 | } else { 91 | 92 | //获取图片路径 93 | [imgLibTool.lib assetForURL:assetURL resultBlock:^(ALAsset *asset) { 94 | if (asset) { 95 | 96 | [_arrSelected addObject:asset]; 97 | [self finishSelectImg]; 98 | [picker dismissViewControllerAnimated:NO completion:nil]; 99 | } 100 | } failureBlock:^(NSError *error) { 101 | 102 | }]; 103 | } 104 | }]; 105 | } 106 | 107 | } 108 | #pragma mark - 完成选择后返回的图片Array(ALAsset*) 109 | - (void)finishSelectImg{ 110 | //正方形缩略图 111 | NSMutableArray *thumbnailImgArr = [NSMutableArray array]; 112 | 113 | for (ALAsset *set in _arrSelected) { 114 | CGImageRef cgImg = [set thumbnail]; 115 | UIImage* image = [UIImage imageWithCGImage: cgImg]; 116 | [thumbnailImgArr addObject:image]; 117 | } 118 | if (self.delegate && [self.delegate respondsToSelector:@selector(getSelectImageWithALAssetArray:thumbnailImageArray:)]) { 119 | [self.delegate getSelectImageWithALAssetArray:_arrSelected thumbnailImageArray:thumbnailImgArr]; 120 | } 121 | } 122 | 123 | 124 | @end 125 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWPhotoCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // XWPhotoCell.h 3 | // XWPublishDemo 4 | // 5 | // Created by 邱学伟 on 16/4/15. 6 | // Copyright © 2016年 邱学伟. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface XWPhotoCell : UICollectionViewCell 12 | 13 | @property (strong, nonatomic) IBOutlet UIImageView *profilePhoto; 14 | @property (strong, nonatomic) IBOutlet UIButton *closeButton; 15 | 16 | @property(nonatomic,strong) UIImageView *BigImgView; 17 | 18 | /** 查看大图 */ 19 | - (void)setBigImgViewWithImage:(UIImage *)img; 20 | 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWPhotoCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // XWPhotoCell.m 3 | // XWPublishDemo 4 | // 5 | // Created by 邱学伟 on 16/4/15. 6 | // Copyright © 2016年 邱学伟. All rights reserved. 7 | // 8 | 9 | #import "XWPhotoCell.h" 10 | 11 | @implementation XWPhotoCell 12 | 13 | /** 查看大图 */ 14 | - (void)setBigImgViewWithImage:(UIImage *)img{ 15 | if (_BigImgView) { 16 | //如果大图正在显示,还原小图 17 | _BigImgView.frame = _profilePhoto.frame; 18 | _BigImgView.image = img; 19 | }else{ 20 | _BigImgView = [[UIImageView alloc] initWithImage:img]; 21 | _BigImgView.frame = _profilePhoto.frame; 22 | [self insertSubview:_BigImgView atIndex:0]; 23 | } 24 | _BigImgView.contentMode = UIViewContentModeScaleToFill; 25 | } 26 | 27 | - (void)awakeFromNib { 28 | [super awakeFromNib]; 29 | // Initialization code 30 | } 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWPhotoCell.xib: -------------------------------------------------------------------------------- 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 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWPublishBaseController.h: -------------------------------------------------------------------------------- 1 | // 2 | // XWPublishBaseController.h 3 | // XWPublishDemo 4 | // 5 | // Created by 邱学伟 on 16/4/15. 6 | // Copyright © 2016年 邱学伟. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import "XWPhotoCell.h" 12 | #import "JJPhotoManeger.h" 13 | #import "XWImagePickerSheet.h" 14 | 15 | @protocol XWPublishBaseViewDelegate 16 | 17 | @optional 18 | 19 | @end 20 | 21 | @interface XWPublishBaseController : UIViewController 22 | 23 | @property (nonatomic, assign) id delegate; 24 | 25 | @property (nonatomic, strong) UICollectionView *pickerCollectionView; 26 | 27 | @property (nonatomic, assign) CGFloat collectionFrameY; 28 | 29 | //选择的图片数据 30 | @property(nonatomic,strong) NSMutableArray *arrSelected; 31 | 32 | //方形压缩图image 数组 33 | @property(nonatomic,strong) NSMutableArray * imageArray; 34 | 35 | //大图image 数组 36 | @property(nonatomic,strong) NSMutableArray * bigImageArray; 37 | 38 | //大图image 二进制 39 | @property(nonatomic,strong) NSMutableArray * bigImgDataArray; 40 | 41 | //图片选择器 42 | @property(nonatomic,strong) UIViewController *showActionSheetViewController; 43 | 44 | //collectionView所在view 45 | @property(nonatomic,strong) UIView *showInView; 46 | 47 | //图片总数量限制 48 | @property(nonatomic,assign) NSInteger maxCount; 49 | 50 | 51 | //初始化collectionView 52 | - (void)initPickerView; 53 | //修改collectionView的位置 54 | - (void)updatePickerViewFrameY:(CGFloat)Y; 55 | //获得collectionView 的 Frame 56 | - (CGRect)getPickerViewFrame; 57 | 58 | //获取选中的所有图片信息 59 | - (NSArray*)getSmallImageArray; 60 | - (NSArray*)getBigImageArray; 61 | - (NSArray*)getALAssetArray; 62 | 63 | - (void)pickerViewFrameChanged; 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /Classes/XWPublish/XWPublishController.h: -------------------------------------------------------------------------------- 1 | // 2 | // XWPublishController.h 3 | // XWPublishDemo 4 | // 5 | // Created by 邱学伟 on 16/4/15. 6 | // Copyright © 2016年 邱学伟. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "XWPublishBaseController.h" 11 | 12 | @interface XWPublishController : XWPublishBaseController 13 | /** 14 | * 取消按钮+监听方法 15 | */ 16 | @property (weak, nonatomic) IBOutlet UIButton *cancelBtn; 17 | - (IBAction)cancelClick:(UIButton *)sender; 18 | /** 19 | * title文字 默认分享新鲜事可在xib修改 20 | */ 21 | @property (weak, nonatomic) IBOutlet UILabel *titleLB; 22 | 23 | 24 | //背景 25 | @property(nonatomic,strong) UIView *noteTextBackgroudView; 26 | 27 | //备注 28 | @property(nonatomic,strong) UITextView *noteTextView; 29 | 30 | //文字个数提示label 31 | @property(nonatomic,strong) UILabel *textNumberLabel; 32 | 33 | //文字说明 34 | @property(nonatomic,strong) UILabel *explainLabel; 35 | 36 | //发布按钮 37 | @property(nonatomic,strong) UIButton *submitBtn; 38 | 39 | 40 | 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /Classes/XWPublish/images/close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qxuewei/XWPublish/15f107959ec45c7e9f5a30479f4f21947b069de9/Classes/XWPublish/images/close.png -------------------------------------------------------------------------------- /Classes/XWPublish/images/close@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qxuewei/XWPublish/15f107959ec45c7e9f5a30479f4f21947b069de9/Classes/XWPublish/images/close@2x.png -------------------------------------------------------------------------------- /Classes/XWPublish/images/close@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qxuewei/XWPublish/15f107959ec45c7e9f5a30479f4f21947b069de9/Classes/XWPublish/images/close@3x.png -------------------------------------------------------------------------------- /Classes/XWPublish/images/ico_check_nomal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qxuewei/XWPublish/15f107959ec45c7e9f5a30479f4f21947b069de9/Classes/XWPublish/images/ico_check_nomal.png -------------------------------------------------------------------------------- /Classes/XWPublish/images/ico_check_nomal@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qxuewei/XWPublish/15f107959ec45c7e9f5a30479f4f21947b069de9/Classes/XWPublish/images/ico_check_nomal@2x.png -------------------------------------------------------------------------------- /Classes/XWPublish/images/ico_check_nomal@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qxuewei/XWPublish/15f107959ec45c7e9f5a30479f4f21947b069de9/Classes/XWPublish/images/ico_check_nomal@3x.png -------------------------------------------------------------------------------- /Classes/XWPublish/images/ico_check_select.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qxuewei/XWPublish/15f107959ec45c7e9f5a30479f4f21947b069de9/Classes/XWPublish/images/ico_check_select.png -------------------------------------------------------------------------------- /Classes/XWPublish/images/ico_check_select@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qxuewei/XWPublish/15f107959ec45c7e9f5a30479f4f21947b069de9/Classes/XWPublish/images/ico_check_select@2x.png -------------------------------------------------------------------------------- /Classes/XWPublish/images/ico_check_select@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qxuewei/XWPublish/15f107959ec45c7e9f5a30479f4f21947b069de9/Classes/XWPublish/images/ico_check_select@3x.png -------------------------------------------------------------------------------- /Classes/XWPublish/images/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qxuewei/XWPublish/15f107959ec45c7e9f5a30479f4f21947b069de9/Classes/XWPublish/images/plus.png -------------------------------------------------------------------------------- /Classes/XWPublish/images/plus@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qxuewei/XWPublish/15f107959ec45c7e9f5a30479f4f21947b069de9/Classes/XWPublish/images/plus@2x.png -------------------------------------------------------------------------------- /Classes/XWPublish/images/plus@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qxuewei/XWPublish/15f107959ec45c7e9f5a30479f4f21947b069de9/Classes/XWPublish/images/plus@3x.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # XWPublish 2 | iOS 10以后需要在info.plist文件中额外加相机系统权限 3 | ``` 4 | NSPhotoLibraryUsageDescription 5 | 系统使用您的相机权限 6 | ``` 7 | 发布状态 8 | ======= 9 | 10 | 两行代码集成发布功能: 11 |

12 | XWPublishController *publishVC = [[XWPublishController alloc] init];
13 | [self presentViewController:publishVC animated:YES completion:nil];
14 | 
15 | 16 | 17 | 效果图: 18 | ![](https://github.com/qxuewei/XWPublish/raw/master/演示gif/publicGif.gif) 19 | 20 | 具体使用方法: 21 | -- 22 | *1.导入'XWPublish'文件夹到项目中 23 | *2.导入 ' #import "XWPublishController.h" ' 24 | *3.在需要发布的按钮点击方法中 25 | *XWPublishController *publishVC = [[XWPublishController alloc] init]; 26 | *[self presentViewController:publishVC animated:YES completion:nil]; 27 | 28 | -- 29 | *在XWPublishController.m中submitToServer方法中编写上传服务器的代码 30 | 31 | ----- 32 | *textfield或者textview中长按出现的(全选,复制,粘贴)显示成中文 33 | 如果在文本输入框中长按复制,粘贴为英文,可以在info.plist中添加Localized resources can be mixed,设置为YES. 34 | 来获取当前手机的语言 35 | 36 | 37 | [ 我的博客 ]( http://blog.csdn.net/qxuewei ) 38 | -------------------------------------------------------------------------------- /XWPublishDemo/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qxuewei/XWPublish/15f107959ec45c7e9f5a30479f4f21947b069de9/XWPublishDemo/.DS_Store -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qxuewei/XWPublish/15f107959ec45c7e9f5a30479f4f21947b069de9/XWPublishDemo/XWPublishDemo/.DS_Store -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // XWPublishDemo 4 | // 5 | // Created by 邱学伟 on 16/4/15. 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 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // XWPublishDemo 4 | // 5 | // Created by 邱学伟 on 16/4/15. 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 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/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 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/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 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NSCameraUsageDescription 6 | 是否允许此App使用您的相机 7 | NSMicrophoneUsageDescription 8 | 是否允许此App使用您的麦克风 9 | NSPhotoLibraryUsageDescription 10 | 系统使用您的相机权限 11 | NSContactsUsageDescription 12 | 是否允许此App访问您的通讯录? 13 | NSLocationAlwaysUsageDescription 14 | 是否允许此App访问您的地理位置? 15 | NSLocationWhenInUseUsageDescription 16 | 是否允许此App访问您的地理位置? 17 | NSBluetoothPeripheralUsageDescription 18 | 是否许允此App使用蓝牙? 19 | NSCalendarsUsageDescription 20 | 是否允许此App使用日历? 21 | NSPhotoLibraryAddUsageDescription 22 | 系统使用您的相机权限 23 | CFBundleAllowMixedLocalizations 24 | 25 | CFBundleDevelopmentRegion 26 | en 27 | CFBundleDisplayName 28 | 发布演示 29 | CFBundleExecutable 30 | $(EXECUTABLE_NAME) 31 | CFBundleIdentifier 32 | $(PRODUCT_BUNDLE_IDENTIFIER) 33 | CFBundleInfoDictionaryVersion 34 | 6.0 35 | CFBundleName 36 | $(PRODUCT_NAME) 37 | CFBundlePackageType 38 | APPL 39 | CFBundleShortVersionString 40 | 1.0 41 | CFBundleSignature 42 | ???? 43 | CFBundleVersion 44 | 1 45 | LSRequiresIPhoneOS 46 | 47 | UILaunchStoryboardName 48 | LaunchScreen 49 | UIMainStoryboardFile 50 | Main 51 | UIRequiredDeviceCapabilities 52 | 53 | armv7 54 | 55 | UISupportedInterfaceOrientations 56 | 57 | UIInterfaceOrientationPortrait 58 | UIInterfaceOrientationLandscapeRight 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/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 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/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 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/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 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/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 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/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 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/SDWebImage/SDWebImageDecoder.m: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the SDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * Created by james on 9/28/11. 6 | * 7 | * For the full copyright and license information, please view the LICENSE 8 | * file that was distributed with this source code. 9 | */ 10 | 11 | #import "SDWebImageDecoder.h" 12 | 13 | @implementation UIImage (ForceDecode) 14 | 15 | + (UIImage *)decodedImageWithImage:(UIImage *)image { 16 | // while downloading huge amount of images 17 | // autorelease the bitmap context 18 | // and all vars to help system to free memory 19 | // when there are memory warning. 20 | // on iOS7, do not forget to call 21 | // [[SDImageCache sharedImageCache] clearMemory]; 22 | 23 | if (image == nil) { // Prevent "CGBitmapContextCreateImage: invalid context 0x0" error 24 | return nil; 25 | } 26 | 27 | @autoreleasepool{ 28 | // do not decode animated images 29 | if (image.images != nil) { 30 | return image; 31 | } 32 | 33 | CGImageRef imageRef = image.CGImage; 34 | 35 | CGImageAlphaInfo alpha = CGImageGetAlphaInfo(imageRef); 36 | BOOL anyAlpha = (alpha == kCGImageAlphaFirst || 37 | alpha == kCGImageAlphaLast || 38 | alpha == kCGImageAlphaPremultipliedFirst || 39 | alpha == kCGImageAlphaPremultipliedLast); 40 | if (anyAlpha) { 41 | return image; 42 | } 43 | 44 | // current 45 | CGColorSpaceModel imageColorSpaceModel = CGColorSpaceGetModel(CGImageGetColorSpace(imageRef)); 46 | CGColorSpaceRef colorspaceRef = CGImageGetColorSpace(imageRef); 47 | 48 | BOOL unsupportedColorSpace = (imageColorSpaceModel == kCGColorSpaceModelUnknown || 49 | imageColorSpaceModel == kCGColorSpaceModelMonochrome || 50 | imageColorSpaceModel == kCGColorSpaceModelCMYK || 51 | imageColorSpaceModel == kCGColorSpaceModelIndexed); 52 | if (unsupportedColorSpace) { 53 | colorspaceRef = CGColorSpaceCreateDeviceRGB(); 54 | } 55 | 56 | size_t width = CGImageGetWidth(imageRef); 57 | size_t height = CGImageGetHeight(imageRef); 58 | NSUInteger bytesPerPixel = 4; 59 | NSUInteger bytesPerRow = bytesPerPixel * width; 60 | NSUInteger bitsPerComponent = 8; 61 | 62 | 63 | // kCGImageAlphaNone is not supported in CGBitmapContextCreate. 64 | // Since the original image here has no alpha info, use kCGImageAlphaNoneSkipLast 65 | // to create bitmap graphics contexts without alpha info. 66 | CGContextRef context = CGBitmapContextCreate(NULL, 67 | width, 68 | height, 69 | bitsPerComponent, 70 | bytesPerRow, 71 | colorspaceRef, 72 | kCGBitmapByteOrderDefault|kCGImageAlphaNoneSkipLast); 73 | 74 | // Draw the image into the context and retrieve the new bitmap image without alpha 75 | CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef); 76 | CGImageRef imageRefWithoutAlpha = CGBitmapContextCreateImage(context); 77 | UIImage *imageWithoutAlpha = [UIImage imageWithCGImage:imageRefWithoutAlpha 78 | scale:image.scale 79 | orientation:image.imageOrientation]; 80 | 81 | if (unsupportedColorSpace) { 82 | CGColorSpaceRelease(colorspaceRef); 83 | } 84 | 85 | CGContextRelease(context); 86 | CGImageRelease(imageRefWithoutAlpha); 87 | 88 | return imageWithoutAlpha; 89 | } 90 | } 91 | 92 | @end 93 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/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 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/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 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/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 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/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 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/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 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/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 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/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 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/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 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/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 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/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 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // XWPublishDemo 4 | // 5 | // Created by 邱学伟 on 16/4/15. 6 | // Copyright © 2016年 邱学伟. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // XWPublishDemo 4 | // 5 | // Created by 邱学伟 on 16/4/15. 6 | // Copyright © 2016年 邱学伟. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "XWPublishController.h" 11 | 12 | @interface ViewController () 13 | 14 | @end 15 | 16 | @implementation ViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | // Do any additional setup after loading the view, typically from a nib. 21 | } 22 | - (IBAction)publish:(id)sender { 23 | XWPublishController *publishVC = [[XWPublishController alloc] init]; 24 | [self presentViewController:publishVC animated:YES completion:nil]; 25 | } 26 | 27 | 28 | 29 | - (void)didReceiveMemoryWarning { 30 | [super didReceiveMemoryWarning]; 31 | // Dispose of any resources that can be recreated. 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/CollectionViewInfo/MFlowLayOut.h: -------------------------------------------------------------------------------- 1 | // 2 | // MFlowLayOut.h 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/10. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MFlowLayOut : UICollectionViewFlowLayout 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/CollectionViewInfo/MFlowLayOut.m: -------------------------------------------------------------------------------- 1 | // 2 | // MFlowLayOut.m 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/10. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 8 | 9 | #import "MFlowLayOut.h" 10 | #import "MHeaderImaCell.h" 11 | @implementation MFlowLayOut 12 | 13 | /* 14 | // Only override drawRect: if you perform custom drawing. 15 | // An empty implementation adversely affects performance during animation. 16 | - (void)drawRect:(CGRect)rect { 17 | // Drawing code 18 | } 19 | */ 20 | - (NSArray *) layoutAttributesForElementsInRect:(CGRect)rect { 21 | 22 | 23 | NSArray *arr = [super layoutAttributesForElementsInRect:rect]; 24 | 25 | 26 | for (UICollectionViewLayoutAttributes *att in arr) { 27 | if (att.representedElementCategory == UICollectionElementCategoryCell) { 28 | MHeaderImaCell *cell = (MHeaderImaCell *)[self.collectionView cellForItemAtIndexPath:att.indexPath]; 29 | 30 | float offSet_x = fabs(self.collectionView.contentOffset.x - (att.frame.origin.x - CGRectGetWidth(self.collectionView.frame))); 31 | CGRect cellRect = cell.btnCheckMark.frame; 32 | cellRect.origin.x = MIN(offSet_x>MHeaderImaCellBtn_width?offSet_x-MHeaderImaCellBtn_width:0, fabs(CGRectGetWidth(att.frame) - CGRectGetWidth(cell.btnCheckMark.frame))); 33 | cell.btnCheckMark.frame = cellRect; 34 | 35 | } 36 | } 37 | 38 | return arr; 39 | } 40 | 41 | - (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds { 42 | 43 | return YES; 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/CollectionViewInfo/MHeadImaView.h: -------------------------------------------------------------------------------- 1 | // 2 | // MHeadImaView.h 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/10. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 仿QQ照片选择器 8 | 9 | #import 10 | 11 | typedef enum { 12 | 13 | headImaCheckMark = 1, 14 | headImaSelectBig = 2, 15 | headImaCheckCancel = 3 16 | 17 | }headImaSelectType; 18 | 19 | @protocol MHeadImaViewDelegate 20 | 21 | - (void)selectIndex:(NSUInteger)index headImaSelectType:(headImaSelectType)type; 22 | 23 | @end 24 | 25 | @interface MHeadImaView : UIView 26 | 27 | @property (nonatomic, weak) id delegate; 28 | - (void)reloadDataWithArr:(NSArray *)arrData arrSelected:(NSMutableArray *)arrSelected; 29 | @end 30 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/CollectionViewInfo/MHeadImaView.m: -------------------------------------------------------------------------------- 1 | // 2 | // MHeadImaView.m 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/10. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 8 | 9 | #import "MHeadImaView.h" 10 | #import "MFlowLayOut.h" 11 | #import "MHeaderImaCell.h" 12 | #import "MImaLibTool.h" 13 | #import 14 | @interface MHeadImaView () 15 | @property (nonatomic, strong) UICollectionView *collectionView; 16 | @property (nonatomic,strong) NSArray *arrData; 17 | @property (nonatomic, strong) NSMutableArray *arrSelected; 18 | @end 19 | 20 | @implementation MHeadImaView 21 | 22 | - (instancetype)initWithFrame:(CGRect)frame { 23 | 24 | if (self = [super initWithFrame:frame]) { 25 | 26 | MFlowLayOut *flowLayout = [[MFlowLayOut alloc] init]; 27 | flowLayout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5); 28 | flowLayout.minimumInteritemSpacing = 5; 29 | flowLayout.minimumLineSpacing = 5; 30 | flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal; 31 | 32 | self.collectionView = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:flowLayout]; 33 | self.collectionView.backgroundColor = [UIColor whiteColor]; 34 | self.collectionView.delegate = self; 35 | self.collectionView.dataSource = self; 36 | self.collectionView.showsHorizontalScrollIndicator = NO; 37 | self.collectionView.showsVerticalScrollIndicator = NO; 38 | [self addSubview:self.collectionView]; 39 | [self.collectionView registerClass:[MHeaderImaCell class] forCellWithReuseIdentifier:MHeaderImaCellClassName]; 40 | 41 | } 42 | return self; 43 | } 44 | 45 | - (void)reloadDataWithArr:(NSArray *)arrData arrSelected:(NSMutableArray *)arrSelected{ 46 | 47 | self.arrSelected = arrSelected; 48 | self.arrData = arrData; 49 | [self.collectionView.collectionViewLayout invalidateLayout]; 50 | [self.collectionView reloadData]; 51 | 52 | 53 | } 54 | 55 | - (CGSize)getImaSizeWithAsset:(ALAsset *)set { 56 | 57 | CGSize imaSize ; 58 | ALAssetRepresentation *sentation = [set defaultRepresentation]; 59 | float scale = sentation.dimensions.width/sentation.dimensions.height; 60 | imaSize.width = floor(180*scale); 61 | imaSize.height = 180; 62 | return imaSize; 63 | } 64 | 65 | #pragma mark - collectionViewDatasourceAndDelegate 66 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { 67 | 68 | return self.arrData.count; 69 | } 70 | 71 | - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 72 | 73 | MHeaderImaCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:MHeaderImaCellClassName forIndexPath:indexPath]; 74 | cell.backgroundColor = [UIColor grayColor]; 75 | ALAsset *set = self.arrData[indexPath.row]; 76 | ALAssetRepresentation *sentation = [set defaultRepresentation]; 77 | cell.imavHead.image = [UIImage imageWithCGImage:[sentation fullScreenImage]]; 78 | cell.btnCheckMark.selected = [[MImaLibTool shareMImaLibTool] imaInArrImasWithArr:self.arrSelected set:set]; 79 | __weak typeof(self) weakSelf = self; 80 | [cell setBtnSelectedActionBlock:^(BOOL state) { 81 | 82 | if (state) { 83 | [weakSelf.arrSelected addObject:set]; 84 | } else { 85 | [weakSelf.arrSelected removeObject:set]; 86 | } 87 | if ([weakSelf.delegate respondsToSelector:@selector(selectIndex:headImaSelectType:)]) { 88 | [weakSelf.delegate selectIndex:indexPath.row headImaSelectType:(state)?headImaCheckMark:headImaCheckCancel]; 89 | } 90 | 91 | }]; 92 | return cell; 93 | } 94 | 95 | 96 | - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { 97 | if ([self.delegate respondsToSelector:@selector(selectIndex:headImaSelectType:)]) { 98 | [self.delegate selectIndex:indexPath.row headImaSelectType:headImaSelectBig]; 99 | } 100 | 101 | } 102 | 103 | - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { 104 | 105 | if (self.arrData.count > 0) { 106 | return [self getImaSizeWithAsset:self.arrData[indexPath.row]]; 107 | } 108 | 109 | return CGSizeZero; 110 | 111 | } 112 | 113 | /* 114 | // Only override drawRect: if you perform custom drawing. 115 | // An empty implementation adversely affects performance during animation. 116 | - (void)drawRect:(CGRect)rect { 117 | // Drawing code 118 | } 119 | */ 120 | 121 | @end 122 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/CollectionViewInfo/MHeaderImaCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // MHeaderImaCell.h 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/10. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "ImagePickerDefine.h" 11 | static NSString *const MHeaderImaCellClassName = @"MHeaderImaCell"; 12 | static float MHeaderImaCellBtn_x_space = 5; 13 | static float MHeaderImaCellBtn_width = 40; 14 | @interface MHeaderImaCell : UICollectionViewCell 15 | @property (nonatomic, strong) UIButton *btnCheckMark; 16 | @property (nonatomic, strong) UIImageView *imavHead; 17 | - (void)setBtnSelectedActionBlock:(MBoolBlock)block; 18 | @end 19 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/CollectionViewInfo/MHeaderImaCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // MHeaderImaCell.m 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/10. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 8 | 9 | #import "MHeaderImaCell.h" 10 | 11 | @implementation MHeaderImaCell 12 | { 13 | 14 | MBoolBlock _actionBlock; 15 | } 16 | - (instancetype)initWithFrame:(CGRect)frame { 17 | 18 | if (self = [super initWithFrame:frame]) { 19 | 20 | 21 | self.clipsToBounds = YES; 22 | self.imavHead = [[UIImageView alloc] initWithFrame:self.bounds]; 23 | self.imavHead.clipsToBounds = YES; 24 | [self addSubview:self.imavHead]; 25 | 26 | self.btnCheckMark = [UIButton buttonWithType:UIButtonTypeCustom]; 27 | self.btnCheckMark.frame = CGRectMake(CGRectGetWidth(self.frame)-MHeaderImaCellBtn_width, 0, MHeaderImaCellBtn_width, MHeaderImaCellBtn_width); 28 | [self.btnCheckMark addTarget:self action:@selector(actionBtn:) forControlEvents:UIControlEventTouchUpInside]; 29 | [self addSubview:self.btnCheckMark]; 30 | 31 | [self.btnCheckMark setImage:[UIImage imageNamed:@"ico_check_select@2x.png"] forState:UIControlStateSelected]; 32 | [self.btnCheckMark setImage:[UIImage imageNamed:@"ico_check_nomal@2x.png"] forState:UIControlStateNormal]; 33 | } 34 | return self; 35 | } 36 | 37 | - (void)actionBtn:(UIButton *)btn { 38 | 39 | btn.selected = !btn.selected; 40 | (!_actionBlock)?:_actionBlock(btn.selected); 41 | } 42 | 43 | - (void)setBtnSelectedActionBlock:(MBoolBlock)block { 44 | 45 | _actionBlock = block; 46 | } 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/JJPhotoViewer/JJMainScrollView.h: -------------------------------------------------------------------------------- 1 | // 2 | // JJMainScrollView.h 3 | // test 4 | // 5 | // Created by KimBox on 15/4/28. 6 | // Copyright (c) 2015年 KimBox. All rights reserved. 7 | // 8 | 9 | 10 | typedef enum { 11 | JJLocalWithLocalPhotoViewer, //点击前是本地图,点击后也是本地图 12 | JJInternetWithInternetPhotoViewer //点击前是网络图,点击后也是网络图 13 | }JJPhotoViewerType; 14 | 15 | #import 16 | 17 | 18 | 19 | @protocol JJPhotoDelegate 20 | 21 | @optional 22 | //关闭PhotoViewer时调用并返回 (观看的最后一张图片的序号) 23 | -(void)photoViwerWilldealloc:(NSInteger)selecedImageViewIndex; 24 | @end 25 | 26 | 27 | @interface JJMainScrollView : UIScrollView 28 | 29 | 30 | //获取数据 31 | -(void)setPhotoData:(NSArray *)photoArr Type:(JJPhotoViewerType)type; 32 | 33 | /**代理*/ 34 | @property(nonatomic,weak)id mainDelegate; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/JJPhotoViewer/JJOneScrollView.h: -------------------------------------------------------------------------------- 1 | // 2 | // JJOneScrollView.h 3 | // test 4 | // 5 | // Created by KimBox on 15/5/4. 6 | // Copyright (c) 2015年 KimBox. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @protocol JJOneScrollViewDelegate 12 | 13 | -(void)goBack; 14 | 15 | -(void)willGoBack:(NSInteger)seletedIndex; 16 | 17 | @optional 18 | 19 | @end 20 | @interface JJOneScrollView : UIScrollView 21 | 22 | 23 | //代理 24 | @property(nonatomic,weak)id mydelegate; 25 | 26 | /**浏览器中我是第几个图片?*/ 27 | @property(nonatomic,assign)NSInteger myindex; 28 | 29 | 30 | 31 | //❤️本地加载图 32 | -(void)setLocalImage:(UIImageView *)imageView ; 33 | 34 | //❤️网络加载图 35 | -(void)setNetWorkImage:(UIImageView *)imageView urlStr:(NSString *)urlStr ; 36 | 37 | 38 | //回复放大缩小前的原状 39 | -(void)reloadFrame; 40 | 41 | 42 | 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/JJPhotoViewer/JJPhoto.h: -------------------------------------------------------------------------------- 1 | // 2 | // JJPhoto.h 3 | // test 4 | // 5 | // Created by KimBox on 15/4/28. 6 | // Copyright (c) 2015年 KimBox. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface JJPhoto : NSObject 13 | 14 | /**点进来的小图片ImageView*/ 15 | @property(nonatomic,strong)UIImageView *imageView; 16 | 17 | /**要显示的网络地址*/ 18 | @property(nonatomic,copy)NSString *urlStr; 19 | 20 | /**holdimage*/ 21 | @property(nonatomic,assign)CGRect oldRect; 22 | 23 | /**是不是点进来的那个ImageView*/ 24 | @property(nonatomic,assign)BOOL isSelecImageView; 25 | 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/JJPhotoViewer/JJPhoto.m: -------------------------------------------------------------------------------- 1 | // 2 | // JJPhoto.m 3 | // test 4 | // 5 | // Created by KimBox on 15/4/28. 6 | // Copyright (c) 2015年 KimBox. All rights reserved. 7 | // 8 | 9 | #import "JJPhoto.h" 10 | 11 | @implementation JJPhoto 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/JJPhotoViewer/JJPhotoManeger.h: -------------------------------------------------------------------------------- 1 | // 2 | // JJPhotoManeger.h 3 | // test 4 | // 5 | // Created by KimBox on 15/4/28. 6 | // Copyright (c) 2015年 KimBox. All rights reserved. 7 | // 8 | 9 | 10 | 11 | 12 | #import 13 | #import 14 | //view 15 | #import "JJMainScrollView.h" 16 | 17 | 18 | @interface JJPhotoManeger : NSObject 19 | /** 20 | * 创建 21 | */ 22 | +(instancetype)maneger; 23 | 24 | /** 25 | 代理 26 | */ 27 | @property(nonatomic,weak)id delegate; 28 | 29 | 30 | 31 | 32 | #pragma mark - ❤️俩核心功能 33 | 34 | /** 35 | * 本地图片放大浏览 36 | */ 37 | -(void)showLocalPhotoViewer:(NSArray *)imageViews selecImageindex:(NSInteger)selecImageindex; 38 | 39 | 40 | /** 41 | * 放大浏览网络图片 42 | */ 43 | -(void)showNetworkPhotoViewer:(NSArray *)imageViews urlStrArr:(NSArray *)urlStrArr selecImageindex:(NSInteger)selecImageindex; 44 | 45 | 46 | 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/JJPhotoViewer/JJPhotoManeger.m: -------------------------------------------------------------------------------- 1 | // 2 | // JJPhotoManeger.m 3 | // test 4 | // 5 | // Created by KimBox on 15/4/28. 6 | // Copyright (c) 2015年 KimBox. All rights reserved. 7 | // 8 | 9 | #import "JJPhotoManeger.h" 10 | //model 11 | #import "JJPhoto.h" 12 | 13 | 14 | @implementation JJPhotoManeger 15 | 16 | /** 17 | * 创建 18 | */ 19 | +(instancetype)maneger 20 | { 21 | JJPhotoManeger *mg = [[JJPhotoManeger alloc]init]; 22 | return mg; 23 | } 24 | 25 | 26 | /** 27 | * 本地图片放大浏览 28 | */ 29 | -(void)showLocalPhotoViewer:(NSArray *)imageViews selecImageindex:(NSInteger)selecImageindex 30 | { 31 | [self setUpPhotoData:imageViews selecImageindex:selecImageindex urlStrArr:nil type:JJLocalWithLocalPhotoViewer]; 32 | } 33 | 34 | 35 | /** 36 | * 点击网络下载图片浏览 37 | */ 38 | -(void)showNetworkPhotoViewer:(NSArray *)imageViews urlStrArr:(NSArray *)urlStrArr selecImageindex:(NSInteger)selecImageindex 39 | { 40 | 41 | [self setUpPhotoData:imageViews selecImageindex:selecImageindex urlStrArr:urlStrArr type:JJInternetWithInternetPhotoViewer]; 42 | } 43 | 44 | 45 | 46 | //拿到数据设置整体页面 47 | -(void)setUpPhotoData:(NSArray *)imageViews selecImageindex:(NSInteger)selecImageindex urlStrArr:(NSArray *)urlStrArr type:(JJPhotoViewerType)type 48 | { 49 | 50 | 51 | //创建模型数组 52 | NSMutableArray *photoModelArr = [NSMutableArray array]; 53 | 54 | 55 | for (int i = 0; i < imageViews.count; i ++) { 56 | 57 | //创建模型 58 | JJPhoto *photo = [[JJPhoto alloc]init]; 59 | 60 | //取出imageView 61 | UIImageView *imageView = imageViews[i]; 62 | 63 | //包装模型 64 | photo.imageView = imageView; 65 | 66 | //如果是网络看图模式 67 | if(type == JJInternetWithInternetPhotoViewer) 68 | { 69 | //包装网络地址 70 | if(i >= urlStrArr.count || urlStrArr == nil ) 71 | { 72 | photo.urlStr = @""; 73 | }else 74 | { 75 | photo.urlStr = urlStrArr[i]; 76 | } 77 | } 78 | 79 | //包装信息:这个imageView是不是点击进来的时候的imageView 80 | if(i == (int)selecImageindex){ 81 | photo.isSelecImageView = YES; 82 | }else{ 83 | photo.isSelecImageView = NO; 84 | } 85 | 86 | //放入模型数组 87 | [photoModelArr addObject:photo]; 88 | } 89 | 90 | //传模型包给主滚动窗 91 | JJMainScrollView *mainScrollView = [[JJMainScrollView alloc]init]; 92 | //传递代理 93 | mainScrollView.mainDelegate = self.delegate; 94 | //给数据 type:然后说明是本地加载/还是网络加载 95 | [mainScrollView setPhotoData:photoModelArr Type:type]; 96 | //展示 97 | [self show:mainScrollView]; 98 | 99 | } 100 | 101 | 102 | //展示 103 | -(void)show:(UIScrollView *)mainScrollView 104 | { 105 | //创建原始的底层View一个 106 | UIView *view = [[UIView alloc]init]; 107 | view.frame = [UIApplication sharedApplication].keyWindow.rootViewController.view.bounds; 108 | [view addSubview:mainScrollView]; 109 | // [[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:view]; 110 | 111 | UIWindow *window = [[UIApplication sharedApplication] keyWindow]; 112 | NSArray *windowViews = [window subviews]; 113 | if(windowViews && [windowViews count] > 0){ 114 | UIView *subView = [windowViews objectAtIndex:[windowViews count]-1]; 115 | for(UIView *aSubView in subView.subviews) 116 | { 117 | [aSubView.layer removeAllAnimations]; 118 | } 119 | [subView addSubview:view]; 120 | } 121 | } 122 | 123 | 124 | 125 | 126 | 127 | @end 128 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/JJPhotoViewer/none.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qxuewei/XWPublish/15f107959ec45c7e9f5a30479f4f21947b069de9/XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/JJPhotoViewer/none.png -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/MImgpicker/ImagePickerDefine.h: -------------------------------------------------------------------------------- 1 | // 2 | // Define.h 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/11. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 8 | 9 | #ifndef QQImagePicker_Define_h 10 | #define QQImagePicker_Define_h 11 | 12 | typedef void (^MBasicBlock)(); 13 | typedef void (^MIndexBlock)(int index); 14 | typedef void (^MobjBlock)(id obj); 15 | typedef void (^MBoolBlock)(BOOL state); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/MImgpicker/MGroupCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // MGroupCell.h 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/11. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | static NSString *const MGroupCellClassName = @"MGroupCell"; 12 | @interface MGroupCell : UITableViewCell 13 | @property (weak, nonatomic) IBOutlet UIImageView *imavHead; 14 | @property (weak, nonatomic) IBOutlet UILabel *lblInfo; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/MImgpicker/MGroupCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // MGroupCell.m 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/11. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 8 | 9 | #import "MGroupCell.h" 10 | 11 | @implementation MGroupCell 12 | 13 | - (void)awakeFromNib { 14 | // Initialization code 15 | // self.lblInfo.textColor = [UIColor colorWithRed:51 green:51 blue:51 alpha:1]; 16 | 17 | if([[[UIDevice currentDevice] systemVersion] floatValue] > 8.0){ 18 | self.layoutMargins = UIEdgeInsetsZero; 19 | self.preservesSuperviewLayoutMargins = NO; 20 | } 21 | self.separatorInset = UIEdgeInsetsMake(0, 60, 0, 0); 22 | self.clipsToBounds = YES; 23 | self.selectionStyle = UITableViewCellSelectionStyleNone; 24 | } 25 | 26 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated { 27 | [super setSelected:selected animated:animated]; 28 | 29 | // Configure the view for the selected state 30 | } 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/MImgpicker/MGroupCell.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/MImgpicker/MImaCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // MImaCell.h 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/11. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "ImagePickerDefine.h" 11 | 12 | @protocol MImaCellDelegate 13 | 14 | - (BOOL)arrayIsfulled; 15 | 16 | @end 17 | 18 | static NSString *MImaCellClassName = @"MImaCell"; 19 | 20 | @interface MImaCell : UICollectionViewCell 21 | 22 | @property(nonatomic,assign) id delegate; 23 | 24 | @property (weak, nonatomic) IBOutlet UIImageView *imavHead; 25 | @property (weak, nonatomic) IBOutlet UIButton *btnCheckMark; 26 | 27 | 28 | @property(nonatomic,strong) UIImageView *BigImgView; 29 | 30 | - (void)setBtnSelectedHandle:(MBoolBlock)block; 31 | 32 | - (void)setBigImgViewWithImage:(UIImage *)img; 33 | @end 34 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/MImgpicker/MImaCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // MImaCell.m 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/11. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 8 | 9 | #import "MImaCell.h" 10 | 11 | @implementation MImaCell 12 | { 13 | 14 | MBoolBlock _boolBlock; 15 | } 16 | - (void)awakeFromNib { 17 | // Initialization code 18 | [self.btnCheckMark setImage:[UIImage imageNamed:@"ico_check_select@2x.png"] forState:UIControlStateSelected]; 19 | } 20 | 21 | - (void)setBtnSelectedHandle:(MBoolBlock)block { 22 | 23 | _boolBlock = block; 24 | } 25 | 26 | - (IBAction)actionBtn:(id)sender { 27 | if ([self.delegate arrayIsfulled] && !self.btnCheckMark.selected) { 28 | return; 29 | } 30 | self.btnCheckMark.selected = !self.btnCheckMark.selected; 31 | (!_boolBlock) ?: _boolBlock(self.btnCheckMark.selected); 32 | } 33 | 34 | - (void)setBigImgViewWithImage:(UIImage *)img{ 35 | if (_BigImgView) { 36 | return; 37 | } 38 | _BigImgView = [[UIImageView alloc]initWithImage:img]; 39 | _BigImgView.frame = _imavHead.frame; 40 | [self insertSubview:_BigImgView atIndex:0]; 41 | } 42 | @end 43 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/MImgpicker/MImaCell.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/MImgpicker/MImaLibTool.h: -------------------------------------------------------------------------------- 1 | // 2 | // MImaLibTool.h 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/11. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | typedef void (^arrBlock)(NSArray *arrObj); 13 | @interface MImaLibTool : NSObject 14 | + (id)shareMImaLibTool; 15 | 16 | 17 | - (void)getAllGroupWithArrObj:(arrBlock)block; 18 | - (NSArray *)getAllAssetsWithGroup:(ALAssetsGroup *)group; 19 | //- (void)getAllAssetsWithGroup:(ALAssetsGroup *)group finishBlock:(arrBlock)block; 20 | 21 | - (BOOL)imaInArrImasWithArr:(NSArray *)arrIma set:(ALAsset *)set; 22 | - (NSArray *)checkMarkSameSetWithArr:(NSArray *)arrSelected set:(ALAsset *)set; 23 | 24 | @property (nonatomic, strong) ALAssetsLibrary *lib; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/MImgpicker/MImaLibTool.m: -------------------------------------------------------------------------------- 1 | // 2 | // MImaLibTool.m 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/11. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 8 | 9 | #import "MImaLibTool.h" 10 | 11 | @interface MImaLibTool () 12 | 13 | @end 14 | 15 | @implementation MImaLibTool 16 | 17 | + (id)shareMImaLibTool { 18 | 19 | static MImaLibTool *tool; 20 | static dispatch_once_t once; 21 | dispatch_once(&once, ^{ 22 | 23 | tool = [[[self class] alloc] init]; 24 | tool.lib = [[ALAssetsLibrary alloc] init]; 25 | }); 26 | 27 | return tool; 28 | } 29 | 30 | 31 | 32 | - (NSArray *)checkMarkSameSetWithArr:(NSArray *)arrSelected set:(ALAsset *)set { 33 | NSString *urlstring = set.defaultRepresentation.url.absoluteString; 34 | NSPredicate *pre = [NSPredicate predicateWithFormat:@"SELF.defaultRepresentation.url.absoluteString == %@",urlstring]; 35 | NSArray *arr = [arrSelected filteredArrayUsingPredicate:pre]; 36 | return arr; 37 | } 38 | 39 | - (BOOL)imaInArrImasWithArr:(NSArray *)arrIma set:(ALAsset *)set { 40 | 41 | // NSString *uti = set.defaultRepresentation.UTI; 42 | // NSString *UTI = [[[arrIma lastObject] defaultRepresentation] UTI]; 43 | return [self checkMarkSameSetWithArr:arrIma set:set].count > 0; 44 | } 45 | 46 | - (void)getAllGroupWithArrObj:(arrBlock)block { 47 | 48 | 49 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 50 | 51 | NSMutableArray *arrGroup = [NSMutableArray array]; 52 | [_lib enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) { 53 | 54 | if (group) { 55 | [arrGroup addObject:group]; 56 | } else { 57 | dispatch_async(dispatch_get_main_queue(), ^{ 58 | if (arrGroup.count > 0) { 59 | (!block)?:block([arrGroup copy]); 60 | } 61 | }); 62 | } 63 | 64 | 65 | } failureBlock:^(NSError *error) { 66 | 67 | }]; 68 | 69 | 70 | }); 71 | 72 | } 73 | 74 | - (NSArray *)getAllAssetsWithGroup:(ALAssetsGroup *)group { 75 | 76 | NSMutableArray *arr = [NSMutableArray array]; 77 | 78 | [group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { 79 | if (result) { 80 | [arr addObject:result]; 81 | } 82 | }]; 83 | return [arr copy]; 84 | } 85 | 86 | 87 | @end 88 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/MImgpicker/MShowAllGroup.h: -------------------------------------------------------------------------------- 1 | // 2 | // MShowAllGroup.h 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/11. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MShowGroupAllSet.h" 11 | 12 | @protocol MShowAllGroupDelegate 13 | -(void)finishSelectImg; 14 | @end 15 | 16 | @interface MShowAllGroup : UIViewController 17 | 18 | @property(nonatomic,assign) id delegate; 19 | 20 | - (id)initWithArrGroup:(NSArray *)arrGroup arrSelected:(NSMutableArray *)arrSelected; 21 | @property (nonatomic, strong) NSMutableArray *arrSeleted; 22 | 23 | @property(nonatomic,strong) MShowGroupAllSet *mvc; 24 | 25 | //图片总数量限制 26 | @property(nonatomic,assign)NSInteger maxCout; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/MImgpicker/MShowAllGroup.m: -------------------------------------------------------------------------------- 1 | // 2 | // MShowAllGroup.m 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/11. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 8 | 9 | #import "MShowAllGroup.h" 10 | #import "MGroupCell.h" 11 | #import 12 | #import "MImaLibTool.h" 13 | 14 | @interface MShowAllGroup () 15 | 16 | @property (nonatomic, strong) NSArray *arrGroup; 17 | @property (nonatomic, strong) UITableView *tableView; 18 | 19 | 20 | @end 21 | 22 | @implementation MShowAllGroup 23 | 24 | - (id)initWithArrGroup:(NSArray *)arrGroup arrSelected:(NSMutableArray *)arr { 25 | 26 | if (self = [super init]) { 27 | 28 | self.arrSeleted = arr; 29 | self.arrGroup = arrGroup; 30 | } 31 | return self; 32 | } 33 | 34 | - (void)viewDidLoad { 35 | [super viewDidLoad]; 36 | self.title = @"照片"; 37 | self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds]; 38 | self.tableView.delegate = self; 39 | self.tableView.dataSource = self; 40 | self.tableView.tableFooterView = [UIView new]; 41 | self.tableView.rowHeight = 50; 42 | [self.view addSubview:self.tableView]; 43 | 44 | [self.tableView registerNib:[UINib nibWithNibName:MGroupCellClassName bundle:nil] forCellReuseIdentifier:MGroupCellClassName]; 45 | 46 | UIBarButtonItem *rightBar = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(actionRightBar)]; 47 | self.navigationItem.rightBarButtonItem = rightBar; 48 | // Do any additional setup after loading the view. 49 | } 50 | 51 | 52 | - (void)actionRightBar { 53 | 54 | [self.navigationController dismissViewControllerAnimated:YES completion:nil]; 55 | } 56 | 57 | #pragma mark - tableDelegate 58 | 59 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 60 | 61 | return self.arrGroup.count; 62 | } 63 | 64 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 65 | 66 | MGroupCell *cell = [tableView dequeueReusableCellWithIdentifier:MGroupCellClassName]; 67 | ALAssetsGroup *froup = self.arrGroup[indexPath.row]; 68 | cell.lblInfo.text = [NSString stringWithFormat:@"%@(%ld)",[froup valueForProperty:ALAssetsGroupPropertyName],[froup numberOfAssets]]; 69 | cell.imavHead.image = [UIImage imageWithCGImage:froup.posterImage]; 70 | return cell; 71 | } 72 | 73 | 74 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 75 | 76 | // if (!_mvc) { 77 | // _mvc = [[MShowGroupAllSet alloc] initWithGroup:self.arrGroup[indexPath.row] selectedArr:self.arrSeleted]; 78 | // _mvc.delegate = self; 79 | // } 80 | // else{ 81 | // _mvc.arrSelected = _arrSeleted; 82 | // } 83 | 84 | _mvc = [[MShowGroupAllSet alloc] initWithGroup:self.arrGroup[indexPath.row] selectedArr:self.arrSeleted]; 85 | _mvc.delegate = self; 86 | _mvc.arrSelected = _arrSeleted; 87 | 88 | 89 | _mvc.MaxCount = _maxCout; 90 | [self.navigationController pushViewController:_mvc animated:YES]; 91 | } 92 | 93 | - (void)didReceiveMemoryWarning { 94 | [super didReceiveMemoryWarning]; 95 | } 96 | 97 | - (void)finishSelectImg{ 98 | [self.delegate finishSelectImg]; 99 | } 100 | 101 | @end 102 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/MImgpicker/MShowGroupAllSet.h: -------------------------------------------------------------------------------- 1 | // 2 | // MShowGroupAllSet.h 3 | // QQImagePicker 4 | // 5 | // Created by mark on 15/9/11. 6 | // Copyright (c) 2015年 mark. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import "JJPhotoManeger.h" 12 | @protocol MShowGroupAllSetDelegate 13 | -(void)finishSelectImg; 14 | @end 15 | 16 | @interface MShowGroupAllSet : UIViewController 17 | - (id)initWithGroup:(ALAssetsGroup *)group selectedArr:(NSMutableArray *)arrSelected; 18 | 19 | @property(nonatomic,assign)NSInteger MaxCount; 20 | @property(nonatomic,assign) id delegate; 21 | @property (nonatomic, strong) NSMutableArray *arrSelected; 22 | 23 | @property(nonatomic,strong) NSMutableArray *imgViewArray; 24 | @end 25 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/SDProgressView/Lib/SDBaseProgressView.h: -------------------------------------------------------------------------------- 1 | // 2 | // SDBaseProgressView.h 3 | // SDProgressView 4 | // 5 | // Created by aier on 15-2-19. 6 | // Copyright (c) 2015年 GSD. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #define SDColorMaker(r, g, b, a) [UIColor colorWithRed:((r) / 255.0) green:((g) / 255.0) blue:((b) / 255.0) alpha:(a)] 12 | 13 | #define SDProgressViewItemMargin 10 14 | 15 | #define SDProgressViewFontScale (MIN(self.frame.size.width, self.frame.size.height) / 100.0) 16 | 17 | // 背景颜色 18 | #define SDProgressViewBackgroundColor SDColorMaker(240, 240, 240, 0.9) 19 | 20 | @interface SDBaseProgressView : UIView 21 | 22 | @property (nonatomic, assign) CGFloat progress; 23 | 24 | - (void)setCenterProgressText:(NSString *)text withAttributes:(NSDictionary *)attributes; 25 | 26 | - (void)dismiss; 27 | 28 | + (id)progressView; 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/SDProgressView/Lib/SDBaseProgressView.m: -------------------------------------------------------------------------------- 1 | // 2 | // SDBaseProgressView.m 3 | // SDProgressView 4 | // 5 | // Created by aier on 15-2-19. 6 | // Copyright (c) 2015年 GSD. All rights reserved. 7 | // 8 | 9 | #import "SDBaseProgressView.h" 10 | 11 | @implementation SDBaseProgressView 12 | 13 | - (id)initWithFrame:(CGRect)frame 14 | { 15 | if (self = [super initWithFrame:frame]) { 16 | // self.backgroundColor = SDProgressViewBackgroundColor; 17 | self.backgroundColor = [UIColor clearColor]; 18 | self.layer.cornerRadius = 5; 19 | self.clipsToBounds = YES; 20 | } 21 | return self; 22 | } 23 | 24 | - (void)setProgress:(CGFloat)progress 25 | { 26 | _progress = progress; 27 | 28 | if (progress >= 1.0) { 29 | [self removeFromSuperview]; 30 | } else { 31 | [self setNeedsDisplay]; 32 | } 33 | 34 | } 35 | 36 | - (void)setCenterProgressText:(NSString *)text withAttributes:(NSDictionary *)attributes 37 | { 38 | CGFloat xCenter = self.frame.size.width * 0.5; 39 | CGFloat yCenter = self.frame.size.height * 0.5; 40 | 41 | // 判断系统版本 42 | if ([[UIDevice currentDevice].systemVersion floatValue] >= 7.0) { 43 | CGSize strSize = [text sizeWithAttributes:attributes]; 44 | CGFloat strX = xCenter - strSize.width * 0.5; 45 | CGFloat strY = yCenter - strSize.height * 0.5; 46 | [text drawAtPoint:CGPointMake(strX, strY) withAttributes:attributes]; 47 | } else { 48 | CGSize strSize; 49 | NSAttributedString *attrStr = nil; 50 | if (attributes[NSFontAttributeName]) { 51 | strSize = [text sizeWithFont:attributes[NSFontAttributeName]]; 52 | attrStr = [[NSAttributedString alloc] initWithString:text attributes:attributes]; 53 | } else { 54 | strSize = [text sizeWithFont:[UIFont systemFontOfSize:[UIFont systemFontSize]]]; 55 | attrStr = [[NSAttributedString alloc] initWithString:text attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:[UIFont systemFontSize]]}]; 56 | } 57 | 58 | CGFloat strX = xCenter - strSize.width * 0.5; 59 | CGFloat strY = yCenter - strSize.height * 0.5; 60 | 61 | [attrStr drawAtPoint:CGPointMake(strX, strY)]; 62 | } 63 | 64 | } 65 | 66 | // 清除指示器 67 | - (void)dismiss 68 | { 69 | self.progress = 1.0; 70 | } 71 | 72 | + (id)progressView 73 | { 74 | return [[self alloc] init]; 75 | } 76 | 77 | @end 78 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/SDProgressView/Lib/SDLoopProgressView.h: -------------------------------------------------------------------------------- 1 | // 2 | // SDLoopProgressView.h 3 | // SDProgressView 4 | // 5 | // Created by aier on 15-2-19. 6 | // Copyright (c) 2015年 GSD. All rights reserved. 7 | // 8 | 9 | #import "SDBaseProgressView.h" 10 | 11 | @interface SDLoopProgressView : SDBaseProgressView 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/SDProgressView/Lib/SDLoopProgressView.m: -------------------------------------------------------------------------------- 1 | // 2 | // SDLoopProgressView.m 3 | // SDProgressView 4 | // 5 | // Created by aier on 15-2-19. 6 | // Copyright (c) 2015年 GSD. All rights reserved. 7 | // 8 | 9 | #import "SDLoopProgressView.h" 10 | 11 | @implementation SDLoopProgressView 12 | 13 | - (void)drawRect:(CGRect)rect 14 | { 15 | CGContextRef ctx = UIGraphicsGetCurrentContext(); 16 | 17 | CGFloat xCenter = rect.size.width * 0.5; 18 | CGFloat yCenter = rect.size.height * 0.5; 19 | [[UIColor whiteColor] set]; 20 | 21 | CGContextSetLineWidth(ctx, 15 * SDProgressViewFontScale); 22 | CGContextSetLineCap(ctx, kCGLineCapRound); 23 | CGFloat to = - M_PI * 0.5 + self.progress * M_PI * 2 + 0.05; // 初始值0.05 24 | CGFloat radius = MIN(rect.size.width, rect.size.height) * 0.5 - SDProgressViewItemMargin; 25 | CGContextAddArc(ctx, xCenter, yCenter, radius, - M_PI * 0.5, to, 0); 26 | CGContextStrokePath(ctx); 27 | 28 | // 进度数字 29 | NSString *progressStr = [NSString stringWithFormat:@"%.0f", self.progress * 100]; 30 | NSMutableDictionary *attributes = [NSMutableDictionary dictionary]; 31 | attributes[NSFontAttributeName] = [UIFont boldSystemFontOfSize:20 * SDProgressViewFontScale]; 32 | attributes[NSForegroundColorAttributeName] = [UIColor whiteColor]; 33 | [self setCenterProgressText:progressStr withAttributes:attributes]; 34 | } 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/SDProgressView/Lib/SDProgressView.h: -------------------------------------------------------------------------------- 1 | // 2 | // SDProgressView.h 3 | // SDProgressView 4 | // 5 | // Created by aier on 15-2-21. 6 | // Copyright (c) 2015年 GSD. All rights reserved. 7 | // 8 | 9 | #import "SDLoopProgressView.h" 10 | #import "SDDemoItemView.h" -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/SDProgressView/View/SDDemoItemView.h: -------------------------------------------------------------------------------- 1 | // 2 | // SDDemoItemView.h 3 | // SDProgressView 4 | // 5 | // Created by aier on 15-2-20. 6 | // Copyright (c) 2015年 GSD. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "SDBaseProgressView.h" 11 | 12 | @interface SDDemoItemView : UIView 13 | 14 | @property (nonatomic, assign) Class progressViewClass; 15 | 16 | @property (nonatomic, strong) SDBaseProgressView *progressView; 17 | 18 | + (id)demoItemViewWithClass:(Class)class; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/Lib/SDProgressView/View/SDDemoItemView.m: -------------------------------------------------------------------------------- 1 | // 2 | // SDDemoItemView.m 3 | // SDProgressView 4 | // 5 | // Created by aier on 15-2-20. 6 | // Copyright (c) 2015年 GSD. All rights reserved. 7 | // 8 | 9 | #import "SDDemoItemView.h" 10 | 11 | @implementation SDDemoItemView 12 | 13 | - (id)initWithFrame:(CGRect)frame 14 | { 15 | self = [super initWithFrame:frame]; 16 | if (self) { 17 | } 18 | return self; 19 | } 20 | 21 | - (void)setProgressViewClass:(Class)progressViewClass 22 | { 23 | _progressViewClass = progressViewClass; 24 | self.progressView = [[progressViewClass alloc] init]; 25 | [self addSubview:self.progressView]; 26 | } 27 | 28 | 29 | + (id)demoItemViewWithClass:(Class)class 30 | { 31 | SDDemoItemView *demo = [[self alloc] init]; 32 | demo.progressViewClass = class; 33 | return demo; 34 | } 35 | 36 | - (void)layoutSubviews 37 | { 38 | [super layoutSubviews]; 39 | self.progressView.frame = self.bounds; 40 | } 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/XWImagePickerSheet.h: -------------------------------------------------------------------------------- 1 | // 2 | // XWImagePickerSheet.h 3 | // XWPublishDemo 4 | // 5 | // Created by 邱学伟 on 16/4/15. 6 | // Copyright © 2016年 邱学伟. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import "MHeadImaView.h" 12 | #import "MImaLibTool.h" 13 | #import "MShowAllGroup.h" 14 | 15 | typedef enum { 16 | selectSend = 1, 17 | selectedCancel = 2, 18 | selectedCamera = 3, 19 | selectPhotoLib = 4 20 | }menuSelectedType; 21 | 22 | //定义选择的block方法 23 | typedef void (^menuSelectBlock)(id obj, menuSelectedType type); 24 | 25 | //协议 26 | @protocol XWImagePickerSheetDelegate 27 | 28 | @optional 29 | /** 30 | * 相册完成选择得到图片 31 | */ 32 | -(void)getSelectImageWithALAssetArray:(NSArray *)ALAssetArray thumbnailImageArray:(NSArray *)thumbnailImgArray; 33 | 34 | @end 35 | 36 | @interface XWImagePickerSheet : NSObject{ 37 | UIImagePickerController *imaPic; 38 | UIViewController *viewController; 39 | } 40 | //代理 41 | @property (nonatomic, assign) id delegate; 42 | @property (nonatomic, strong) UITableView *tableview; 43 | @property (nonatomic, strong) NSArray *arrTitles; 44 | @property (nonatomic, copy) menuSelectBlock menuBlock; 45 | @property (nonatomic, strong) NSArray *arrGroup; 46 | @property (nonatomic, strong) NSMutableArray *arrSelected; 47 | @property (nonatomic, assign) NSInteger maxCount; 48 | //显示选择照片提示sheet 49 | -(void)showImgPickerActionSheetInView:(UIViewController *)controller; 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWImagePicker/XWImagePickerSheet.m: -------------------------------------------------------------------------------- 1 | // 2 | // XWImagePickerSheet.m 3 | // XWPublishDemo 4 | // 5 | // Created by 邱学伟 on 16/4/15. 6 | // Copyright © 2016年 邱学伟. All rights reserved. 7 | // 8 | 9 | #import "XWImagePickerSheet.h" 10 | 11 | @interface XWImagePickerSheet () 12 | 13 | @end 14 | 15 | @implementation XWImagePickerSheet 16 | -(instancetype)init{ 17 | self = [super init]; 18 | if (self) { 19 | if (!_arrSelected) { 20 | self.arrSelected = [NSMutableArray array]; 21 | } 22 | } 23 | return self; 24 | } 25 | //显示选择照片提示Sheet 26 | -(void)showImgPickerActionSheetInView:(UIViewController *)controller{ 27 | UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"选择照片" preferredStyle:UIAlertControllerStyleActionSheet]; 28 | UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { 29 | 30 | }]; 31 | UIAlertAction *actionCamera = [UIAlertAction actionWithTitle:[NSString stringWithFormat:@"拍照"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { 32 | if (!imaPic) { 33 | imaPic = [[UIImagePickerController alloc] init]; 34 | } 35 | if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { 36 | imaPic.sourceType = UIImagePickerControllerSourceTypeCamera; 37 | imaPic.delegate = self; 38 | [viewController presentViewController:imaPic animated:NO completion:nil]; 39 | } 40 | 41 | }]; 42 | UIAlertAction *actionAlbum = [UIAlertAction actionWithTitle:[NSString stringWithFormat:@"相册"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { 43 | [self loadImgDataAndShowAllGroup]; 44 | }]; 45 | [alertController addAction:actionCancel]; 46 | [alertController addAction:actionCamera]; 47 | [alertController addAction:actionAlbum]; 48 | viewController = controller; 49 | [viewController presentViewController:alertController animated:YES completion:nil]; 50 | 51 | } 52 | #pragma mark - 加载照片数据 53 | - (void)loadImgDataAndShowAllGroup{ 54 | if (!_arrSelected) { 55 | self.arrSelected = [NSMutableArray array]; 56 | } 57 | [[MImaLibTool shareMImaLibTool] getAllGroupWithArrObj:^(NSArray *arrObj) { 58 | if (arrObj && arrObj.count > 0) { 59 | self.arrGroup = arrObj; 60 | if ( self.arrGroup.count > 0) { 61 | MShowAllGroup *svc = [[MShowAllGroup alloc] initWithArrGroup:self.arrGroup arrSelected:self.arrSelected]; 62 | svc.delegate = self; 63 | UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:svc]; 64 | if (_arrSelected) { 65 | svc.arrSeleted = _arrSelected; 66 | svc.mvc.arrSelected = _arrSelected; 67 | } 68 | svc.maxCout = _maxCount; 69 | [viewController presentViewController:nav animated:YES completion:nil]; 70 | } 71 | } 72 | }]; 73 | } 74 | #pragma mark - 拍照获得数据 75 | -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ 76 | UIImage *theImage = nil; 77 | // 判断,图片是否允许修改 78 | if ([picker allowsEditing]){ 79 | //获取用户编辑之后的图像 80 | theImage = [info objectForKey:UIImagePickerControllerEditedImage]; 81 | } else { 82 | // 照片的元数据参数 83 | theImage = [info objectForKey:UIImagePickerControllerOriginalImage]; 84 | } 85 | if (theImage) { 86 | //保存图片到相册中 87 | MImaLibTool *imgLibTool = [MImaLibTool shareMImaLibTool]; 88 | [imgLibTool.lib writeImageToSavedPhotosAlbum:[theImage CGImage] orientation:(ALAssetOrientation)[theImage imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){ 89 | if (error) { 90 | } else { 91 | 92 | //获取图片路径 93 | [imgLibTool.lib assetForURL:assetURL resultBlock:^(ALAsset *asset) { 94 | if (asset) { 95 | 96 | [_arrSelected addObject:asset]; 97 | [self finishSelectImg]; 98 | [picker dismissViewControllerAnimated:NO completion:nil]; 99 | } 100 | } failureBlock:^(NSError *error) { 101 | 102 | }]; 103 | } 104 | }]; 105 | } 106 | 107 | } 108 | #pragma mark - 完成选择后返回的图片Array(ALAsset*) 109 | - (void)finishSelectImg{ 110 | //正方形缩略图 111 | NSMutableArray *thumbnailImgArr = [NSMutableArray array]; 112 | 113 | for (ALAsset *set in _arrSelected) { 114 | CGImageRef cgImg = [set thumbnail]; 115 | UIImage* image = [UIImage imageWithCGImage: cgImg]; 116 | [thumbnailImgArr addObject:image]; 117 | } 118 | if (self.delegate && [self.delegate respondsToSelector:@selector(getSelectImageWithALAssetArray:thumbnailImageArray:)]) { 119 | [self.delegate getSelectImageWithALAssetArray:_arrSelected thumbnailImageArray:thumbnailImgArr]; 120 | } 121 | } 122 | 123 | 124 | @end 125 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWPhotoCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // XWPhotoCell.h 3 | // XWPublishDemo 4 | // 5 | // Created by 邱学伟 on 16/4/15. 6 | // Copyright © 2016年 邱学伟. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface XWPhotoCell : UICollectionViewCell 12 | 13 | @property (strong, nonatomic) IBOutlet UIImageView *profilePhoto; 14 | @property (strong, nonatomic) IBOutlet UIButton *closeButton; 15 | 16 | @property(nonatomic,strong) UIImageView *BigImgView; 17 | 18 | /** 查看大图 */ 19 | - (void)setBigImgViewWithImage:(UIImage *)img; 20 | 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWPhotoCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // XWPhotoCell.m 3 | // XWPublishDemo 4 | // 5 | // Created by 邱学伟 on 16/4/15. 6 | // Copyright © 2016年 邱学伟. All rights reserved. 7 | // 8 | 9 | #import "XWPhotoCell.h" 10 | 11 | @implementation XWPhotoCell 12 | 13 | /** 查看大图 */ 14 | - (void)setBigImgViewWithImage:(UIImage *)img{ 15 | if (_BigImgView) { 16 | //如果大图正在显示,还原小图 17 | _BigImgView.frame = _profilePhoto.frame; 18 | _BigImgView.image = img; 19 | }else{ 20 | _BigImgView = [[UIImageView alloc] initWithImage:img]; 21 | _BigImgView.frame = _profilePhoto.frame; 22 | [self insertSubview:_BigImgView atIndex:0]; 23 | } 24 | _BigImgView.contentMode = UIViewContentModeScaleToFill; 25 | } 26 | 27 | - (void)awakeFromNib { 28 | [super awakeFromNib]; 29 | // Initialization code 30 | } 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWPhotoCell.xib: -------------------------------------------------------------------------------- 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 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWPublishBaseController.h: -------------------------------------------------------------------------------- 1 | // 2 | // XWPublishBaseController.h 3 | // XWPublishDemo 4 | // 5 | // Created by 邱学伟 on 16/4/15. 6 | // Copyright © 2016年 邱学伟. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import "XWPhotoCell.h" 12 | #import "JJPhotoManeger.h" 13 | #import "XWImagePickerSheet.h" 14 | 15 | @protocol XWPublishBaseViewDelegate 16 | 17 | @optional 18 | 19 | @end 20 | 21 | @interface XWPublishBaseController : UIViewController 22 | 23 | @property (nonatomic, assign) id delegate; 24 | 25 | @property (nonatomic, strong) UICollectionView *pickerCollectionView; 26 | 27 | @property (nonatomic, assign) CGFloat collectionFrameY; 28 | 29 | //选择的图片数据 30 | @property(nonatomic,strong) NSMutableArray *arrSelected; 31 | 32 | //方形压缩图image 数组 33 | @property(nonatomic,strong) NSMutableArray * imageArray; 34 | 35 | //大图image 数组 36 | @property(nonatomic,strong) NSMutableArray * bigImageArray; 37 | 38 | //大图image 二进制 39 | @property(nonatomic,strong) NSMutableArray * bigImgDataArray; 40 | 41 | //图片选择器 42 | @property(nonatomic,strong) UIViewController *showActionSheetViewController; 43 | 44 | //collectionView所在view 45 | @property(nonatomic,strong) UIView *showInView; 46 | 47 | //图片总数量限制 48 | @property(nonatomic,assign) NSInteger maxCount; 49 | 50 | 51 | //初始化collectionView 52 | - (void)initPickerView; 53 | //修改collectionView的位置 54 | - (void)updatePickerViewFrameY:(CGFloat)Y; 55 | //获得collectionView 的 Frame 56 | - (CGRect)getPickerViewFrame; 57 | 58 | //获取选中的所有图片信息 59 | - (NSArray*)getSmallImageArray; 60 | - (NSArray*)getBigImageArray; 61 | - (NSArray*)getALAssetArray; 62 | 63 | - (void)pickerViewFrameChanged; 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/XWPublishController.h: -------------------------------------------------------------------------------- 1 | // 2 | // XWPublishController.h 3 | // XWPublishDemo 4 | // 5 | // Created by 邱学伟 on 16/4/15. 6 | // Copyright © 2016年 邱学伟. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "XWPublishBaseController.h" 11 | 12 | @interface XWPublishController : XWPublishBaseController 13 | /** 14 | * 取消按钮+监听方法 15 | */ 16 | @property (weak, nonatomic) IBOutlet UIButton *cancelBtn; 17 | - (IBAction)cancelClick:(UIButton *)sender; 18 | /** 19 | * title文字 默认分享新鲜事可在xib修改 20 | */ 21 | @property (weak, nonatomic) IBOutlet UILabel *titleLB; 22 | 23 | 24 | //背景 25 | @property(nonatomic,strong) UIView *noteTextBackgroudView; 26 | 27 | //备注 28 | @property(nonatomic,strong) UITextView *noteTextView; 29 | 30 | //文字个数提示label 31 | @property(nonatomic,strong) UILabel *textNumberLabel; 32 | 33 | //文字说明 34 | @property(nonatomic,strong) UILabel *explainLabel; 35 | 36 | //发布按钮 37 | @property(nonatomic,strong) UIButton *submitBtn; 38 | 39 | 40 | 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/images/close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qxuewei/XWPublish/15f107959ec45c7e9f5a30479f4f21947b069de9/XWPublishDemo/XWPublishDemo/XWPublish/images/close.png -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/images/close@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qxuewei/XWPublish/15f107959ec45c7e9f5a30479f4f21947b069de9/XWPublishDemo/XWPublishDemo/XWPublish/images/close@2x.png -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/images/close@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qxuewei/XWPublish/15f107959ec45c7e9f5a30479f4f21947b069de9/XWPublishDemo/XWPublishDemo/XWPublish/images/close@3x.png -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/images/ico_check_nomal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qxuewei/XWPublish/15f107959ec45c7e9f5a30479f4f21947b069de9/XWPublishDemo/XWPublishDemo/XWPublish/images/ico_check_nomal.png -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/images/ico_check_nomal@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qxuewei/XWPublish/15f107959ec45c7e9f5a30479f4f21947b069de9/XWPublishDemo/XWPublishDemo/XWPublish/images/ico_check_nomal@2x.png -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/images/ico_check_nomal@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qxuewei/XWPublish/15f107959ec45c7e9f5a30479f4f21947b069de9/XWPublishDemo/XWPublishDemo/XWPublish/images/ico_check_nomal@3x.png -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/images/ico_check_select.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qxuewei/XWPublish/15f107959ec45c7e9f5a30479f4f21947b069de9/XWPublishDemo/XWPublishDemo/XWPublish/images/ico_check_select.png -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/images/ico_check_select@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qxuewei/XWPublish/15f107959ec45c7e9f5a30479f4f21947b069de9/XWPublishDemo/XWPublishDemo/XWPublish/images/ico_check_select@2x.png -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/images/ico_check_select@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qxuewei/XWPublish/15f107959ec45c7e9f5a30479f4f21947b069de9/XWPublishDemo/XWPublishDemo/XWPublish/images/ico_check_select@3x.png -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/images/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qxuewei/XWPublish/15f107959ec45c7e9f5a30479f4f21947b069de9/XWPublishDemo/XWPublishDemo/XWPublish/images/plus.png -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/images/plus@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qxuewei/XWPublish/15f107959ec45c7e9f5a30479f4f21947b069de9/XWPublishDemo/XWPublishDemo/XWPublish/images/plus@2x.png -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/XWPublish/images/plus@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qxuewei/XWPublish/15f107959ec45c7e9f5a30479f4f21947b069de9/XWPublishDemo/XWPublishDemo/XWPublish/images/plus@3x.png -------------------------------------------------------------------------------- /XWPublishDemo/XWPublishDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // XWPublishDemo 4 | // 5 | // Created by 邱学伟 on 16/4/15. 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 | -------------------------------------------------------------------------------- /演示gif/publicGif.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qxuewei/XWPublish/15f107959ec45c7e9f5a30479f4f21947b069de9/演示gif/publicGif.gif --------------------------------------------------------------------------------