├── .gitignore ├── LICENSE ├── MXScrollFramework └── Info.plist ├── MXScrollView.podspec ├── MXScrollView ├── CMSDWebImage │ ├── CMSDImageCache.h │ ├── CMSDImageCache.m │ ├── CMSDWebImageCompat.h │ ├── CMSDWebImageCompat.m │ ├── CMSDWebImageDecoder.h │ ├── CMSDWebImageDecoder.m │ ├── CMSDWebImageDownloader.h │ ├── CMSDWebImageDownloader.m │ ├── CMSDWebImageDownloaderOperation.h │ ├── CMSDWebImageDownloaderOperation.m │ ├── CMSDWebImageManager.h │ ├── CMSDWebImageManager.m │ ├── CMSDWebImageOperation.h │ ├── CMSDWebImagePrefetcher.h │ ├── CMSDWebImagePrefetcher.m │ ├── MKAnnotationView+CMWebCache.h │ ├── MKAnnotationView+CMWebCache.m │ ├── NSData+CMImageContentType.h │ ├── NSData+CMImageContentType.m │ ├── UIButton+CMWebCache.h │ ├── UIButton+CMWebCache.m │ ├── UIImage+CMGIF.h │ ├── UIImage+CMGIF.m │ ├── UIImage+CMMultiFormat.h │ ├── UIImage+CMMultiFormat.m │ ├── UIImage+CMWebP.h │ ├── UIImage+CMWebP.m │ ├── UIImageView+CMHighlightedWebCache.h │ ├── UIImageView+CMHighlightedWebCache.m │ ├── UIImageView+CMWebCache.h │ ├── UIImageView+CMWebCache.m │ ├── UIView+CMWebCacheOperation.h │ └── UIView+CMWebCacheOperation.m ├── MXEnumHeader.h ├── MXImageScrollView.h ├── MXImageScrollView.m ├── MXImageView.h ├── MXImageView.m ├── MXPageControl.h ├── MXPageControl.m ├── MXScrollConst.h ├── MXScrollConst.m ├── MXScrollView.bundle │ └── placeholderPicture.png ├── MXScrollView.h ├── MXTransaction.h └── MXTransaction.m ├── MXScrollViewDemo.xcodeproj ├── project.pbxproj └── xcshareddata │ └── xcschemes │ └── MXScrollFramework.xcscheme ├── MXScrollViewDemo ├── AnimationViewController.h ├── AnimationViewController.m ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ ├── house.imageset │ │ ├── Alarm_213px_1194720_easyicon.net.png │ │ └── Contents.json │ └── island.imageset │ │ ├── Contents.json │ │ └── Sun_128px_1194839_easyicon.net.png ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── EasyUseViewController.h ├── EasyUseViewController.m ├── Info.plist ├── TableUseViewController.h ├── TableUseViewController.m ├── VerticalUseViewController.h ├── VerticalUseViewController.m ├── ViewController.h ├── ViewController.m └── main.m ├── Pictures ├── gif_one.gif ├── gif_two.gif ├── picture_1.png ├── picture_2.png └── picture_3.png └── README.md /.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 | ## Other 21 | *.xccheckout 22 | *.moved-aside 23 | *.xcuserstate 24 | *.xcscmblueprint 25 | 26 | ## Obj-C/Swift specific 27 | *.hmap 28 | *.ipa 29 | 30 | # CocoaPods 31 | # 32 | # We recommend against adding the Pods directory to your .gitignore. However 33 | # you should judge for yourself, the pros and cons are mentioned at: 34 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 35 | # 36 | # Pods/ 37 | 38 | # Carthage 39 | # 40 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 41 | # Carthage/Checkouts 42 | 43 | Carthage/Build 44 | 45 | # fastlane 46 | # 47 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 48 | # screenshots whenever they are needed. 49 | # For more information about the recommended setup visit: 50 | # https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md 51 | 52 | fastlane/report.xml 53 | fastlane/screenshots 54 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /MXScrollFramework/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /MXScrollView.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'MXScrollView' 3 | s.version = '1.2.3' 4 | s.summary = 'The use of a simple with the effects of the rolling cycle view' 5 | s.homepage = 'https://github.com/cwxatlm/MXScrollView' 6 | s.license = 'MIT' 7 | s.authors = {'wx chen' => '524200634@qq.com'} 8 | s.platform = :ios, '6.0' 9 | s.source = {:git => 'https://github.com/cwxatlm/MXScrollView.git', :tag => s.version} 10 | s.source_files = 'MXScrollView/**/*.{h,m}' 11 | s.resource = 'MXScrollView/MXScrollView.bundle' 12 | s.requires_arc = true 13 | end 14 | -------------------------------------------------------------------------------- /MXScrollView/CMSDWebImage/CMSDImageCache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CMSDWebImage 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 "CMSDWebImageCompat.h" 11 | 12 | typedef NS_ENUM(NSInteger, CMSDImageCacheType) { 13 | /** 14 | * The image wasn't available the CMSDWebImage caches, but was downloaded from the web. 15 | */ 16 | CMSDImageCacheTypeNone, 17 | /** 18 | * The image was obtained from the disk cache. 19 | */ 20 | CMSDImageCacheTypeDisk, 21 | /** 22 | * The image was obtained from the memory cache. 23 | */ 24 | CMSDImageCacheTypeMemory 25 | }; 26 | 27 | typedef void(^CMSDWebImageQueryCompletedBlock)(UIImage *image, CMSDImageCacheType cacheType); 28 | 29 | typedef void(^CMSDWebImageCheckCacheCompletionBlock)(BOOL isInCache); 30 | 31 | typedef void(^CMSDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger totalSize); 32 | 33 | /** 34 | * CMSDImageCache maintains a memory cache and an optional disk cache. Disk cache write operations are performed 35 | * asynchronous so it doesn’t add unnecessary latency to the UI. 36 | */ 37 | @interface CMSDImageCache : NSObject 38 | 39 | /** 40 | * Decompressing images that are downloaded and cached can improve performance but can consume lot of memory. 41 | * Defaults to YES. Set this to NO if you are experiencing a crash due to excessive memory consumption. 42 | */ 43 | @property (assign, nonatomic) BOOL shouldDecompressImages; 44 | 45 | /** 46 | * disable iCloud backup [defaults to YES] 47 | */ 48 | @property (assign, nonatomic) BOOL shouldDisableiCloud; 49 | 50 | /** 51 | * use memory cache [defaults to YES] 52 | */ 53 | @property (assign, nonatomic) BOOL shouldCacheImagesInMemory; 54 | 55 | /** 56 | * The maximum "total cost" of the in-memory image cache. The cost function is the number of pixels held in memory. 57 | */ 58 | @property (assign, nonatomic) NSUInteger maxMemoryCost; 59 | 60 | /** 61 | * The maximum number of objects the cache should hold. 62 | */ 63 | @property (assign, nonatomic) NSUInteger maxMemoryCountLimit; 64 | 65 | /** 66 | * The maximum length of time to keep an image in the cache, in seconds 67 | */ 68 | @property (assign, nonatomic) NSInteger maxCacheAge; 69 | 70 | /** 71 | * The maximum size of the cache, in bytes. 72 | */ 73 | @property (assign, nonatomic) NSUInteger maxCacheSize; 74 | 75 | /** 76 | * Returns global shared cache instance 77 | * 78 | * @return CMSDImageCache global instance 79 | */ 80 | + (CMSDImageCache *)sharedImageCache; 81 | 82 | /** 83 | * Init a new cache store with a specific namespace 84 | * 85 | * @param ns The namespace to use for this cache store 86 | */ 87 | - (id)initWithNamespace:(NSString *)ns; 88 | 89 | /** 90 | * Init a new cache store with a specific namespace and directory 91 | * 92 | * @param ns The namespace to use for this cache store 93 | * @param directory Directory to cache disk images in 94 | */ 95 | - (id)initWithNamespace:(NSString *)ns diskCacheDirectory:(NSString *)directory; 96 | 97 | -(NSString *)makeDiskCachePath:(NSString*)fullNamespace; 98 | 99 | /** 100 | * Add a read-only cache path to search for images pre-cached by CMSDImageCache 101 | * Useful if you want to bundle pre-loaded images with your app 102 | * 103 | * @param path The path to use for this read-only cache path 104 | */ 105 | - (void)addReadOnlyCachePath:(NSString *)path; 106 | 107 | /** 108 | * Store an image into memory and disk cache at the given key. 109 | * 110 | * @param image The image to store 111 | * @param key The unique image cache key, usually it's image absolute URL 112 | */ 113 | - (void)storeImage:(UIImage *)image forKey:(NSString *)key; 114 | 115 | /** 116 | * Store an image into memory and optionally disk cache at the given key. 117 | * 118 | * @param image The image to store 119 | * @param key The unique image cache key, usually it's image absolute URL 120 | * @param toDisk Store the image to disk cache if YES 121 | */ 122 | - (void)storeImage:(UIImage *)image forKey:(NSString *)key toDisk:(BOOL)toDisk; 123 | 124 | /** 125 | * Store an image into memory and optionally disk cache at the given key. 126 | * 127 | * @param image The image to store 128 | * @param recalculate BOOL indicates if imageData can be used or a new data should be constructed from the UIImage 129 | * @param imageData The image data as returned by the server, this representation will be used for disk storage 130 | * instead of converting the given image object into a storable/compressed image format in order 131 | * to save quality and CPU 132 | * @param key The unique image cache key, usually it's image absolute URL 133 | * @param toDisk Store the image to disk cache if YES 134 | */ 135 | - (void)storeImage:(UIImage *)image recalculateFromImage:(BOOL)recalculate imageData:(NSData *)imageData forKey:(NSString *)key toDisk:(BOOL)toDisk; 136 | 137 | /** 138 | * Query the disk cache asynchronously. 139 | * 140 | * @param key The unique key used to store the wanted image 141 | */ 142 | - (NSOperation *)queryDiskCacheForKey:(NSString *)key done:(CMSDWebImageQueryCompletedBlock)doneBlock; 143 | 144 | /** 145 | * Query the memory cache synchronously. 146 | * 147 | * @param key The unique key used to store the wanted image 148 | */ 149 | - (UIImage *)imageFromMemoryCacheForKey:(NSString *)key; 150 | 151 | /** 152 | * Query the disk cache synchronously after checking the memory cache. 153 | * 154 | * @param key The unique key used to store the wanted image 155 | */ 156 | - (UIImage *)imageFromDiskCacheForKey:(NSString *)key; 157 | 158 | /** 159 | * Remove the image from memory and disk cache synchronously 160 | * 161 | * @param key The unique image cache key 162 | */ 163 | - (void)removeImageForKey:(NSString *)key; 164 | 165 | 166 | /** 167 | * Remove the image from memory and disk cache asynchronously 168 | * 169 | * @param key The unique image cache key 170 | * @param completion An block that should be executed after the image has been removed (optional) 171 | */ 172 | - (void)removeImageForKey:(NSString *)key withCompletion:(CMSDWebImageNoParamsBlock)completion; 173 | 174 | /** 175 | * Remove the image from memory and optionally disk cache asynchronously 176 | * 177 | * @param key The unique image cache key 178 | * @param fromDisk Also remove cache entry from disk if YES 179 | */ 180 | - (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk; 181 | 182 | /** 183 | * Remove the image from memory and optionally disk cache asynchronously 184 | * 185 | * @param key The unique image cache key 186 | * @param fromDisk Also remove cache entry from disk if YES 187 | * @param completion An block that should be executed after the image has been removed (optional) 188 | */ 189 | - (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk withCompletion:(CMSDWebImageNoParamsBlock)completion; 190 | 191 | /** 192 | * Clear all memory cached images 193 | */ 194 | - (void)clearMemory; 195 | 196 | /** 197 | * Clear all disk cached images. Non-blocking method - returns immediately. 198 | * @param completion An block that should be executed after cache expiration completes (optional) 199 | */ 200 | - (void)clearDiskOnCompletion:(CMSDWebImageNoParamsBlock)completion; 201 | 202 | /** 203 | * Clear all disk cached images 204 | * @see clearDiskOnCompletion: 205 | */ 206 | - (void)clearDisk; 207 | 208 | /** 209 | * Remove all expired cached image from disk. Non-blocking method - returns immediately. 210 | * @param completionBlock An block that should be executed after cache expiration completes (optional) 211 | */ 212 | - (void)cleanDiskWithCompletionBlock:(CMSDWebImageNoParamsBlock)completionBlock; 213 | 214 | /** 215 | * Remove all expired cached image from disk 216 | * @see cleanDiskWithCompletionBlock: 217 | */ 218 | - (void)cleanDisk; 219 | 220 | /** 221 | * Get the size used by the disk cache 222 | */ 223 | - (NSUInteger)getSize; 224 | 225 | /** 226 | * Get the number of images in the disk cache 227 | */ 228 | - (NSUInteger)getDiskCount; 229 | 230 | /** 231 | * Asynchronously calculate the disk cache's size. 232 | */ 233 | - (void)calculateSizeWithCompletionBlock:(CMSDWebImageCalculateSizeBlock)completionBlock; 234 | 235 | /** 236 | * Async check if image exists in disk cache already (does not load the image) 237 | * 238 | * @param key the key describing the url 239 | * @param completionBlock the block to be executed when the check is done. 240 | * @note the completion block will be always executed on the main queue 241 | */ 242 | - (void)diskImageExistsWithKey:(NSString *)key completion:(CMSDWebImageCheckCacheCompletionBlock)completionBlock; 243 | 244 | /** 245 | * Check if image exists in disk cache already (does not load the image) 246 | * 247 | * @param key the key describing the url 248 | * 249 | * @return YES if an image exists for the given key 250 | */ 251 | - (BOOL)diskImageExistsWithKey:(NSString *)key; 252 | 253 | /** 254 | * Get the cache path for a certain key (needs the cache path root folder) 255 | * 256 | * @param key the key (can be obtained from url using cacheKeyForURL) 257 | * @param path the cache path root folder 258 | * 259 | * @return the cache path 260 | */ 261 | - (NSString *)cachePathForKey:(NSString *)key inPath:(NSString *)path; 262 | 263 | /** 264 | * Get the default cache path for a certain key 265 | * 266 | * @param key the key (can be obtained from url using cacheKeyForURL) 267 | * 268 | * @return the default cache path 269 | */ 270 | - (NSString *)defaultCachePathForKey:(NSString *)key; 271 | 272 | @end 273 | -------------------------------------------------------------------------------- /MXScrollView/CMSDWebImage/CMSDWebImageCompat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CMCMSDWebImage 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 CMCMSDWebImage 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 CMCMSDWebImage 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 CMSDDispatchQueueRelease 44 | #undef CMSDDispatchQueueSetterSementics 45 | #define CMSDDispatchQueueRelease(q) 46 | #define CMSDDispatchQueueSetterSementics strong 47 | #else 48 | #undef CMSDDispatchQueueRelease 49 | #undef CMSDDispatchQueueSetterSementics 50 | #define CMSDDispatchQueueRelease(q) (dispatch_release(q)) 51 | #define CMSDDispatchQueueSetterSementics assign 52 | #endif 53 | 54 | extern UIImage *CMSDScaledImageForKey(NSString *key, UIImage *image); 55 | 56 | typedef void(^CMSDWebImageNoParamsBlock)(); 57 | 58 | extern NSString *const CMSDWebImageErrorDomain; 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 | -------------------------------------------------------------------------------- /MXScrollView/CMSDWebImage/CMSDWebImageCompat.m: -------------------------------------------------------------------------------- 1 | // 2 | // CMSDWebImageCompat.m 3 | // CMSDWebImage 4 | // 5 | // Created by Olivier Poitrey on 11/12/12. 6 | // Copyright (c) 2012 Dailymotion. All rights reserved. 7 | // 8 | 9 | #import "CMSDWebImageCompat.h" 10 | 11 | #if !__has_feature(objc_arc) 12 | #error CMSDWebImage is ARC only. Either turn on ARC for the project or use -fobjc-arc flag 13 | #endif 14 | 15 | inline UIImage *CMSDScaledImageForKey(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:CMSDScaledImageForKey(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 CMSDWebImageErrorDomain = @"CMSDWebImageErrorDomain"; 52 | -------------------------------------------------------------------------------- /MXScrollView/CMSDWebImage/CMSDWebImageDecoder.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 "CMSDWebImageCompat.h" 13 | 14 | @interface UIImage (ForceDecode) 15 | 16 | + (UIImage *)decodedImageWithImage:(UIImage *)image; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /MXScrollView/CMSDWebImage/CMSDWebImageDecoder.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 "CMSDWebImageDecoder.h" 12 | 13 | @implementation UIImage (ForceDecode) 14 | 15 | + (UIImage *)decodedImageWithImage:(UIImage *)image { 16 | // while downloading huge amount of images 17 | // autorelease the bitmap context 18 | // and all vars to help system to free memory 19 | // when there are memory warning. 20 | // on iOS7, do not forget to call 21 | // [[SDImageCache sharedImageCache] clearMemory]; 22 | @autoreleasepool{ 23 | // do not decode animated images 24 | if (image.images) { return image; } 25 | 26 | CGImageRef imageRef = image.CGImage; 27 | 28 | CGImageAlphaInfo alpha = CGImageGetAlphaInfo(imageRef); 29 | BOOL anyAlpha = (alpha == kCGImageAlphaFirst || 30 | alpha == kCGImageAlphaLast || 31 | alpha == kCGImageAlphaPremultipliedFirst || 32 | alpha == kCGImageAlphaPremultipliedLast); 33 | 34 | if (anyAlpha) { return image; } 35 | 36 | // current 37 | CGColorSpaceModel imageColorSpaceModel = CGColorSpaceGetModel(CGImageGetColorSpace(imageRef)); 38 | CGColorSpaceRef colorspaceRef = CGImageGetColorSpace(imageRef); 39 | 40 | bool unsupportedColorSpace = (imageColorSpaceModel == 0 || imageColorSpaceModel == -1 || imageColorSpaceModel == kCGColorSpaceModelCMYK || imageColorSpaceModel == kCGColorSpaceModelIndexed); 41 | if (unsupportedColorSpace) 42 | colorspaceRef = CGColorSpaceCreateDeviceRGB(); 43 | 44 | size_t width = CGImageGetWidth(imageRef); 45 | size_t height = CGImageGetHeight(imageRef); 46 | NSUInteger bytesPerPixel = 4; 47 | NSUInteger bytesPerRow = bytesPerPixel * width; 48 | NSUInteger bitsPerComponent = 8; 49 | 50 | CGContextRef context = CGBitmapContextCreate(NULL, 51 | width, 52 | height, 53 | bitsPerComponent, 54 | bytesPerRow, 55 | colorspaceRef, 56 | kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst); 57 | 58 | // Draw the image into the context and retrieve the new image, which will now have an alpha layer 59 | CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef); 60 | CGImageRef imageRefWithAlpha = CGBitmapContextCreateImage(context); 61 | UIImage *imageWithAlpha = [UIImage imageWithCGImage:imageRefWithAlpha scale:image.scale orientation:image.imageOrientation]; 62 | 63 | if (unsupportedColorSpace) 64 | CGColorSpaceRelease(colorspaceRef); 65 | 66 | CGContextRelease(context); 67 | CGImageRelease(imageRefWithAlpha); 68 | 69 | return imageWithAlpha; 70 | } 71 | } 72 | 73 | @end 74 | -------------------------------------------------------------------------------- /MXScrollView/CMSDWebImage/CMSDWebImageDownloader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CMSDWebImage 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 "CMSDWebImageCompat.h" 11 | #import "CMSDWebImageOperation.h" 12 | 13 | typedef NS_OPTIONS(NSUInteger, CMSDWebImageDownloaderOptions) { 14 | CMSDWebImageDownloaderLowPriority = 1 << 0, 15 | CMSDWebImageDownloaderProgressiveDownload = 1 << 1, 16 | 17 | /** 18 | * By default, request prevent the of NSURLCache. With this flag, NSURLCache 19 | * is used with default policies. 20 | */ 21 | CMSDWebImageDownloaderUseNSURLCache = 1 << 2, 22 | 23 | /** 24 | * Call completion block with nil image/imageData if the image was read from NSURLCache 25 | * (to be combined with `CMSDWebImageDownloaderUseNSURLCache`). 26 | */ 27 | 28 | CMSDWebImageDownloaderIgnoreCachedResponse = 1 << 3, 29 | /** 30 | * In iOS 4+, continue the download of the image if the app goes to background. This is achieved by asking the system for 31 | * extra time in background to let the request finish. If the background task expires the operation will be cancelled. 32 | */ 33 | 34 | CMSDWebImageDownloaderContinueInBackground = 1 << 4, 35 | 36 | /** 37 | * Handles cookies stored in NSHTTPCookieStore by setting 38 | * NSMutableURLRequest.HTTPShouldHandleCookies = YES; 39 | */ 40 | CMSDWebImageDownloaderHandleCookies = 1 << 5, 41 | 42 | /** 43 | * Enable to allow untrusted SSL certificates. 44 | * Useful for testing purposes. Use with caution in production. 45 | */ 46 | CMSDWebImageDownloaderAllowInvalidSSLCertificates = 1 << 6, 47 | 48 | /** 49 | * Put the image in the high priority queue. 50 | */ 51 | CMSDWebImageDownloaderHighPriority = 1 << 7, 52 | }; 53 | 54 | typedef NS_ENUM(NSInteger, CMSDWebImageDownloaderExecutionOrder) { 55 | /** 56 | * Default value. All download operations will execute in queue style (first-in-first-out). 57 | */ 58 | CMSDWebImageDownloaderFIFOExecutionOrder, 59 | 60 | /** 61 | * All download operations will execute in stack style (last-in-first-out). 62 | */ 63 | CMSDWebImageDownloaderLIFOExecutionOrder 64 | }; 65 | 66 | extern NSString *const CMSDWebImageDownloadStartNotification; 67 | extern NSString *const CMSDWebImageDownloadStopNotification; 68 | 69 | typedef void(^CMSDWebImageDownloaderProgressBlock)(NSInteger receivedSize, NSInteger expectedSize); 70 | 71 | typedef void(^CMSDWebImageDownloaderCompletedBlock)(UIImage *image, NSData *data, NSError *error, BOOL finished); 72 | 73 | typedef NSDictionary *(^CMSDWebImageDownloaderHeadersFilterBlock)(NSURL *url, NSDictionary *headers); 74 | 75 | /** 76 | * Asynchronous downloader dedicated and optimized for image loading. 77 | */ 78 | @interface CMSDWebImageDownloader : NSObject 79 | 80 | /** 81 | * Decompressing images that are downloaded and cached can improve performance but can consume lot of memory. 82 | * Defaults to YES. Set this to NO if you are experiencing a crash due to excessive memory consumption. 83 | */ 84 | @property (assign, nonatomic) BOOL shouldDecompressImages; 85 | 86 | @property (assign, nonatomic) NSInteger maxConcurrentDownloads; 87 | 88 | /** 89 | * Shows the current amount of downloads that still need to be downloaded 90 | */ 91 | @property (readonly, nonatomic) NSUInteger currentDownloadCount; 92 | 93 | 94 | /** 95 | * The timeout value (in seconds) for the download operation. Default: 15.0. 96 | */ 97 | @property (assign, nonatomic) NSTimeInterval downloadTimeout; 98 | 99 | 100 | /** 101 | * Changes download operations execution order. Default value is `CMSDWebImageDownloaderFIFOExecutionOrder`. 102 | */ 103 | @property (assign, nonatomic) CMSDWebImageDownloaderExecutionOrder executionOrder; 104 | 105 | /** 106 | * Singleton method, returns the shared instance 107 | * 108 | * @return global shared instance of downloader class 109 | */ 110 | + (CMSDWebImageDownloader *)sharedDownloader; 111 | 112 | /** 113 | * Set the default URL credential to be set for request operations. 114 | */ 115 | @property (strong, nonatomic) NSURLCredential *urlCredential; 116 | 117 | /** 118 | * Set username 119 | */ 120 | @property (strong, nonatomic) NSString *username; 121 | 122 | /** 123 | * Set password 124 | */ 125 | @property (strong, nonatomic) NSString *password; 126 | 127 | /** 128 | * Set filter to pick headers for downloading image HTTP request. 129 | * 130 | * This block will be invoked for each downloading image request, returned 131 | * NSDictionary will be used as headers in corresponding HTTP request. 132 | */ 133 | @property (nonatomic, copy) CMSDWebImageDownloaderHeadersFilterBlock headersFilter; 134 | 135 | /** 136 | * Set a value for a HTTP header to be appended to each download HTTP request. 137 | * 138 | * @param value The value for the header field. Use `nil` value to remove the header. 139 | * @param field The name of the header field to set. 140 | */ 141 | - (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field; 142 | 143 | /** 144 | * Returns the value of the specified HTTP header field. 145 | * 146 | * @return The value associated with the header field field, or `nil` if there is no corresponding header field. 147 | */ 148 | - (NSString *)valueForHTTPHeaderField:(NSString *)field; 149 | 150 | /** 151 | * Sets a subclass of `CMSDWebImageDownloaderOperation` as the default 152 | * `NSOperation` to be used each time CMSDWebImage constructs a request 153 | * operation to download an image. 154 | * 155 | * @param operationClass The subclass of `CMSDWebImageDownloaderOperation` to set 156 | * as default. Passing `nil` will revert to `CMSDWebImageDownloaderOperation`. 157 | */ 158 | - (void)setOperationClass:(Class)operationClass; 159 | 160 | /** 161 | * Creates a CMSDWebImageDownloader async downloader instance with a given URL 162 | * 163 | * The delegate will be informed when the image is finish downloaded or an error has happen. 164 | * 165 | * @see CMSDWebImageDownloaderDelegate 166 | * 167 | * @param url The URL to the image to download 168 | * @param options The options to be used for this download 169 | * @param progressBlock A block called repeatedly while the image is downloading 170 | * @param completedBlock A block called once the download is completed. 171 | * If the download succeeded, the image parameter is set, in case of error, 172 | * error parameter is set with the error. The last parameter is always YES 173 | * if CMSDWebImageDownloaderProgressiveDownload isn't use. With the 174 | * CMSDWebImageDownloaderProgressiveDownload option, this block is called 175 | * repeatedly with the partial image object and the finished argument set to NO 176 | * before to be called a last time with the full image and finished argument 177 | * set to YES. In case of error, the finished argument is always YES. 178 | * 179 | * @return A cancellable CMSDWebImageOperation 180 | */ 181 | - (id )downloadImageWithURL:(NSURL *)url 182 | options:(CMSDWebImageDownloaderOptions)options 183 | progress:(CMSDWebImageDownloaderProgressBlock)progressBlock 184 | completed:(CMSDWebImageDownloaderCompletedBlock)completedBlock; 185 | 186 | /** 187 | * Sets the download queue suspension state 188 | */ 189 | - (void)setSuspended:(BOOL)suspended; 190 | 191 | @end 192 | -------------------------------------------------------------------------------- /MXScrollView/CMSDWebImage/CMSDWebImageDownloader.m: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CMSDWebImage 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 "CMSDWebImageDownloader.h" 10 | #import "CMSDWebImageDownloaderOperation.h" 11 | #import 12 | 13 | static NSString *const kProgressCallbackKey = @"progress"; 14 | static NSString *const kCompletedCallbackKey = @"completed"; 15 | 16 | @interface CMSDWebImageDownloader () 17 | 18 | @property (strong, nonatomic) NSOperationQueue *downloadQueue; 19 | @property (weak, nonatomic) NSOperation *lastAddedOperation; 20 | @property (assign, nonatomic) Class operationClass; 21 | @property (strong, nonatomic) NSMutableDictionary *URLCallbacks; 22 | @property (strong, nonatomic) NSMutableDictionary *HTTPHeaders; 23 | // This queue is used to serialize the handling of the network responses of all the download operation in a single queue 24 | @property (CMSDDispatchQueueSetterSementics, nonatomic) dispatch_queue_t barrierQueue; 25 | 26 | @end 27 | 28 | @implementation CMSDWebImageDownloader 29 | 30 | + (void)initialize { 31 | // Bind SDNetworkActivityIndicator if available (download it here: http://github.com/rs/SDNetworkActivityIndicator ) 32 | // To use it, just add #import "SDNetworkActivityIndicator.h" in addition to the CMSDWebImage import 33 | if (NSClassFromString(@"SDNetworkActivityIndicator")) { 34 | 35 | #pragma clang diagnostic push 36 | #pragma clang diagnostic ignored "-Warc-performSelector-leaks" 37 | id activityIndicator = [NSClassFromString(@"SDNetworkActivityIndicator") performSelector:NSSelectorFromString(@"sharedActivityIndicator")]; 38 | #pragma clang diagnostic pop 39 | 40 | // Remove observer in case it was previously added. 41 | [[NSNotificationCenter defaultCenter] removeObserver:activityIndicator name:CMSDWebImageDownloadStartNotification object:nil]; 42 | [[NSNotificationCenter defaultCenter] removeObserver:activityIndicator name:CMSDWebImageDownloadStopNotification object:nil]; 43 | 44 | [[NSNotificationCenter defaultCenter] addObserver:activityIndicator 45 | selector:NSSelectorFromString(@"startActivity") 46 | name:CMSDWebImageDownloadStartNotification object:nil]; 47 | [[NSNotificationCenter defaultCenter] addObserver:activityIndicator 48 | selector:NSSelectorFromString(@"stopActivity") 49 | name:CMSDWebImageDownloadStopNotification object:nil]; 50 | } 51 | } 52 | 53 | + (CMSDWebImageDownloader *)sharedDownloader { 54 | static dispatch_once_t once; 55 | static id instance; 56 | dispatch_once(&once, ^{ 57 | instance = [self new]; 58 | }); 59 | return instance; 60 | } 61 | 62 | - (id)init { 63 | if ((self = [super init])) { 64 | _operationClass = [CMSDWebImageDownloaderOperation class]; 65 | _shouldDecompressImages = YES; 66 | _executionOrder = CMSDWebImageDownloaderFIFOExecutionOrder; 67 | _downloadQueue = [NSOperationQueue new]; 68 | _downloadQueue.maxConcurrentOperationCount = 6; 69 | _URLCallbacks = [NSMutableDictionary new]; 70 | #ifdef SD_WEBP 71 | _HTTPHeaders = [@{@"Accept": @"image/webp,image/*;q=0.8"} mutableCopy]; 72 | #else 73 | _HTTPHeaders = [@{@"Accept": @"image/*;q=0.8"} mutableCopy]; 74 | #endif 75 | _barrierQueue = dispatch_queue_create("com.hackemist.CMSDWebImageDownloaderBarrierQueue", DISPATCH_QUEUE_CONCURRENT); 76 | _downloadTimeout = 15.0; 77 | } 78 | return self; 79 | } 80 | 81 | - (void)dealloc { 82 | [self.downloadQueue cancelAllOperations]; 83 | CMSDDispatchQueueRelease(_barrierQueue); 84 | } 85 | 86 | - (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field { 87 | if (value) { 88 | self.HTTPHeaders[field] = value; 89 | } 90 | else { 91 | [self.HTTPHeaders removeObjectForKey:field]; 92 | } 93 | } 94 | 95 | - (NSString *)valueForHTTPHeaderField:(NSString *)field { 96 | return self.HTTPHeaders[field]; 97 | } 98 | 99 | - (void)setMaxConcurrentDownloads:(NSInteger)maxConcurrentDownloads { 100 | _downloadQueue.maxConcurrentOperationCount = maxConcurrentDownloads; 101 | } 102 | 103 | - (NSUInteger)currentDownloadCount { 104 | return _downloadQueue.operationCount; 105 | } 106 | 107 | - (NSInteger)maxConcurrentDownloads { 108 | return _downloadQueue.maxConcurrentOperationCount; 109 | } 110 | 111 | - (void)setOperationClass:(Class)operationClass { 112 | _operationClass = operationClass ?: [CMSDWebImageDownloaderOperation class]; 113 | } 114 | 115 | - (id )downloadImageWithURL:(NSURL *)url options:(CMSDWebImageDownloaderOptions)options progress:(CMSDWebImageDownloaderProgressBlock)progressBlock completed:(CMSDWebImageDownloaderCompletedBlock)completedBlock { 116 | __block CMSDWebImageDownloaderOperation *operation; 117 | __weak __typeof(self)wself = self; 118 | 119 | [self addProgressCallback:progressBlock completedBlock:completedBlock forURL:url createCallback:^{ 120 | NSTimeInterval timeoutInterval = wself.downloadTimeout; 121 | if (timeoutInterval == 0.0) { 122 | timeoutInterval = 15.0; 123 | } 124 | 125 | // In order to prevent from potential duplicate caching (NSURLCache + SDImageCache) we disable the cache for image requests if told otherwise 126 | NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:(options & CMSDWebImageDownloaderUseNSURLCache ? NSURLRequestUseProtocolCachePolicy : NSURLRequestReloadIgnoringLocalCacheData) timeoutInterval:timeoutInterval]; 127 | request.HTTPShouldHandleCookies = (options & CMSDWebImageDownloaderHandleCookies); 128 | request.HTTPShouldUsePipelining = YES; 129 | if (wself.headersFilter) { 130 | request.allHTTPHeaderFields = wself.headersFilter(url, [wself.HTTPHeaders copy]); 131 | } 132 | else { 133 | request.allHTTPHeaderFields = wself.HTTPHeaders; 134 | } 135 | operation = [[wself.operationClass alloc] initWithRequest:request 136 | options:options 137 | progress:^(NSInteger receivedSize, NSInteger expectedSize) { 138 | CMSDWebImageDownloader *sself = wself; 139 | if (!sself) return; 140 | __block NSArray *callbacksForURL; 141 | dispatch_sync(sself.barrierQueue, ^{ 142 | callbacksForURL = [sself.URLCallbacks[url] copy]; 143 | }); 144 | for (NSDictionary *callbacks in callbacksForURL) { 145 | dispatch_async(dispatch_get_main_queue(), ^{ 146 | CMSDWebImageDownloaderProgressBlock callback = callbacks[kProgressCallbackKey]; 147 | if (callback) callback(receivedSize, expectedSize); 148 | }); 149 | } 150 | } 151 | completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) { 152 | CMSDWebImageDownloader *sself = wself; 153 | if (!sself) return; 154 | __block NSArray *callbacksForURL; 155 | dispatch_barrier_sync(sself.barrierQueue, ^{ 156 | callbacksForURL = [sself.URLCallbacks[url] copy]; 157 | if (finished) { 158 | [sself.URLCallbacks removeObjectForKey:url]; 159 | } 160 | }); 161 | for (NSDictionary *callbacks in callbacksForURL) { 162 | CMSDWebImageDownloaderCompletedBlock callback = callbacks[kCompletedCallbackKey]; 163 | if (callback) callback(image, data, error, finished); 164 | } 165 | } 166 | cancelled:^{ 167 | CMSDWebImageDownloader *sself = wself; 168 | if (!sself) return; 169 | dispatch_barrier_async(sself.barrierQueue, ^{ 170 | [sself.URLCallbacks removeObjectForKey:url]; 171 | }); 172 | }]; 173 | operation.shouldDecompressImages = wself.shouldDecompressImages; 174 | 175 | if (wself.urlCredential) { 176 | operation.credential = wself.urlCredential; 177 | } else if (wself.username && wself.password) { 178 | operation.credential = [NSURLCredential credentialWithUser:wself.username password:wself.password persistence:NSURLCredentialPersistenceForSession]; 179 | } 180 | 181 | if (options & CMSDWebImageDownloaderHighPriority) { 182 | operation.queuePriority = NSOperationQueuePriorityHigh; 183 | } else if (options & CMSDWebImageDownloaderLowPriority) { 184 | operation.queuePriority = NSOperationQueuePriorityLow; 185 | } 186 | 187 | [wself.downloadQueue addOperation:operation]; 188 | if (wself.executionOrder == CMSDWebImageDownloaderLIFOExecutionOrder) { 189 | // Emulate LIFO execution order by systematically adding new operations as last operation's dependency 190 | [wself.lastAddedOperation addDependency:operation]; 191 | wself.lastAddedOperation = operation; 192 | } 193 | }]; 194 | 195 | return operation; 196 | } 197 | 198 | - (void)addProgressCallback:(CMSDWebImageDownloaderProgressBlock)progressBlock completedBlock:(CMSDWebImageDownloaderCompletedBlock)completedBlock forURL:(NSURL *)url createCallback:(CMSDWebImageNoParamsBlock)createCallback { 199 | // The URL will be used as the key to the callbacks dictionary so it cannot be nil. If it is nil immediately call the completed block with no image or data. 200 | if (url == nil) { 201 | if (completedBlock != nil) { 202 | completedBlock(nil, nil, nil, NO); 203 | } 204 | return; 205 | } 206 | 207 | dispatch_barrier_sync(self.barrierQueue, ^{ 208 | BOOL first = NO; 209 | if (!self.URLCallbacks[url]) { 210 | self.URLCallbacks[url] = [NSMutableArray new]; 211 | first = YES; 212 | } 213 | 214 | // Handle single download of simultaneous download request for the same URL 215 | NSMutableArray *callbacksForURL = self.URLCallbacks[url]; 216 | NSMutableDictionary *callbacks = [NSMutableDictionary new]; 217 | if (progressBlock) callbacks[kProgressCallbackKey] = [progressBlock copy]; 218 | if (completedBlock) callbacks[kCompletedCallbackKey] = [completedBlock copy]; 219 | [callbacksForURL addObject:callbacks]; 220 | self.URLCallbacks[url] = callbacksForURL; 221 | 222 | if (first) { 223 | createCallback(); 224 | } 225 | }); 226 | } 227 | 228 | - (void)setSuspended:(BOOL)suspended { 229 | [self.downloadQueue setSuspended:suspended]; 230 | } 231 | 232 | @end 233 | -------------------------------------------------------------------------------- /MXScrollView/CMSDWebImage/CMSDWebImageDownloaderOperation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CMSDWebImage 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 "CMSDWebImageDownloader.h" 11 | #import "CMSDWebImageOperation.h" 12 | 13 | extern NSString *const CMSDWebImageDownloadStartNotification; 14 | extern NSString *const CMSDWebImageDownloadReceiveResponseNotification; 15 | extern NSString *const CMSDWebImageDownloadStopNotification; 16 | extern NSString *const CMSDWebImageDownloadFinishNotification; 17 | 18 | @interface CMSDWebImageDownloaderOperation : 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 CMSDWebImageDownloaderOptions for the receiver. 44 | */ 45 | @property (assign, nonatomic, readonly) CMSDWebImageDownloaderOptions 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 `CMSDWebImageDownloaderOperation` object 59 | * 60 | * @see CMSDWebImageDownloaderOperation 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:(CMSDWebImageDownloaderOptions)options 74 | progress:(CMSDWebImageDownloaderProgressBlock)progressBlock 75 | completed:(CMSDWebImageDownloaderCompletedBlock)completedBlock 76 | cancelled:(CMSDWebImageNoParamsBlock)cancelBlock; 77 | 78 | @end 79 | -------------------------------------------------------------------------------- /MXScrollView/CMSDWebImage/CMSDWebImageManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CMSDWebImage 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 "CMSDWebImageCompat.h" 10 | #import "CMSDWebImageOperation.h" 11 | #import "CMSDWebImageDownloader.h" 12 | #import "CMSDImageCache.h" 13 | 14 | typedef NS_OPTIONS(NSUInteger, CMSDWebImageOptions) { 15 | /** 16 | * By default, when a URL fail to be downloaded, the URL is blacklisted so the library won't keep trying. 17 | * This flag disable this blacklisting. 18 | */ 19 | CMSDWebImageRetryFailed = 1 << 0, 20 | 21 | /** 22 | * By default, image downloads are started during UI interactions, this flags disable this feature, 23 | * leading to delayed download on UIScrollView deceleration for instance. 24 | */ 25 | CMSDWebImageLowPriority = 1 << 1, 26 | 27 | /** 28 | * This flag disables on-disk caching 29 | */ 30 | CMSDWebImageCacheMemoryOnly = 1 << 2, 31 | 32 | /** 33 | * This flag enables progressive download, the image is displayed progressively during download as a browser would do. 34 | * By default, the image is only displayed once completely downloaded. 35 | */ 36 | CMSDWebImageProgressiveDownload = 1 << 3, 37 | 38 | /** 39 | * Even if the image is cached, respect the HTTP response cache control, and refresh the image from remote location if needed. 40 | * The disk caching will be handled by NSURLCache instead of CMSDWebImage leading to slight performance degradation. 41 | * This option helps deal with images changing behind the same request URL, e.g. Facebook graph api profile pics. 42 | * If a cached image is refreshed, the completion block is called once with the cached image and again with the final image. 43 | * 44 | * Use this flag only if you can't make your URLs static with embedded cache busting parameter. 45 | */ 46 | CMSDWebImageRefreshCached = 1 << 4, 47 | 48 | /** 49 | * In iOS 4+, continue the download of the image if the app goes to background. This is achieved by asking the system for 50 | * extra time in background to let the request finish. If the background task expires the operation will be cancelled. 51 | */ 52 | CMSDWebImageContinueInBackground = 1 << 5, 53 | 54 | /** 55 | * Handles cookies stored in NSHTTPCookieStore by setting 56 | * NSMutableURLRequest.HTTPShouldHandleCookies = YES; 57 | */ 58 | CMSDWebImageHandleCookies = 1 << 6, 59 | 60 | /** 61 | * Enable to allow untrusted SSL certificates. 62 | * Useful for testing purposes. Use with caution in production. 63 | */ 64 | CMSDWebImageAllowInvalidSSLCertificates = 1 << 7, 65 | 66 | /** 67 | * By default, image are loaded in the order they were queued. This flag move them to 68 | * the front of the queue and is loaded immediately instead of waiting for the current queue to be loaded (which 69 | * could take a while). 70 | */ 71 | CMSDWebImageHighPriority = 1 << 8, 72 | 73 | /** 74 | * By default, placeholder images are loaded while the image is loading. This flag will delay the loading 75 | * of the placeholder image until after the image has finished loading. 76 | */ 77 | CMSDWebImageDelayPlaceholder = 1 << 9, 78 | 79 | /** 80 | * We usually don't call transformDownloadedImage delegate method on animated images, 81 | * as most transformation code would mangle it. 82 | * Use this flag to transform them anyway. 83 | */ 84 | CMSDWebImageTransformAnimatedImage = 1 << 10, 85 | 86 | /** 87 | * By default, image is added to the imageView after download. But in some cases, we want to 88 | * have the hand before setting the image (apply a filter or add it with cross-fade animation for instance) 89 | * Use this flag if you want to manually set the image in the completion when success 90 | */ 91 | CMSDWebImageAvoidAutoSetImage = 1 << 11 92 | }; 93 | 94 | typedef void(^CMSDWebImageCompletionBlock)(UIImage *image, NSError *error, CMSDImageCacheType cacheType, NSURL *imageURL); 95 | 96 | typedef void(^CMSDWebImageCompletionWithFinishedBlock)(UIImage *image, NSError *error, CMSDImageCacheType cacheType, BOOL finished, NSURL *imageURL); 97 | 98 | typedef NSString *(^CMSDWebImageCacheKeyFilterBlock)(NSURL *url); 99 | 100 | 101 | @class CMSDWebImageManager; 102 | 103 | @protocol CMSDWebImageManagerDelegate 104 | 105 | @optional 106 | 107 | /** 108 | * Controls which image should be downloaded when the image is not found in the cache. 109 | * 110 | * @param imageManager The current `CMSDWebImageManager` 111 | * @param imageURL The url of the image to be downloaded 112 | * 113 | * @return Return NO to prevent the downloading of the image on cache misses. If not implemented, YES is implied. 114 | */ 115 | - (BOOL)imageManager:(CMSDWebImageManager *)imageManager shouldDownloadImageForURL:(NSURL *)imageURL; 116 | 117 | /** 118 | * Allows to transform the image immediately after it has been downloaded and just before to cache it on disk and memory. 119 | * NOTE: This method is called from a global queue in order to not to block the main thread. 120 | * 121 | * @param imageManager The current `CMSDWebImageManager` 122 | * @param image The image to transform 123 | * @param imageURL The url of the image to transform 124 | * 125 | * @return The transformed image object. 126 | */ 127 | - (UIImage *)imageManager:(CMSDWebImageManager *)imageManager transformDownloadedImage:(UIImage *)image withURL:(NSURL *)imageURL; 128 | 129 | @end 130 | 131 | /** 132 | * The CMSDWebImageManager is the class behind the UIImageView+WebCache category and likes. 133 | * It ties the asynchronous downloader (CMSDWebImageDownloader) with the image cache store (CMSDImageCache). 134 | * You can use this class directly to benefit from web image downloading with caching in another context than 135 | * a UIView. 136 | * 137 | * Here is a simple example of how to use CMSDWebImageManager: 138 | * 139 | * @code 140 | 141 | CMSDWebImageManager *manager = [CMSDWebImageManager sharedManager]; 142 | [manager downloadImageWithURL:imageURL 143 | options:0 144 | progress:nil 145 | completed:^(UIImage *image, NSError *error, CMSDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { 146 | if (image) { 147 | // do something with image 148 | } 149 | }]; 150 | 151 | * @endcode 152 | */ 153 | @interface CMSDWebImageManager : NSObject 154 | 155 | @property (weak, nonatomic) id delegate; 156 | 157 | @property (strong, nonatomic, readonly) CMSDImageCache *imageCache; 158 | @property (strong, nonatomic, readonly) CMSDWebImageDownloader *imageDownloader; 159 | 160 | /** 161 | * The cache filter is a block used each time CMSDWebImageManager need to convert an URL into a cache key. This can 162 | * be used to remove dynamic part of an image URL. 163 | * 164 | * The following example sets a filter in the application delegate that will remove any query-string from the 165 | * URL before to use it as a cache key: 166 | * 167 | * @code 168 | 169 | [[CMSDWebImageManager sharedManager] setCacheKeyFilter:^(NSURL *url) { 170 | url = [[NSURL alloc] initWithScheme:url.scheme host:url.host path:url.path]; 171 | return [url absoluteString]; 172 | }]; 173 | 174 | * @endcode 175 | */ 176 | @property (nonatomic, copy) CMSDWebImageCacheKeyFilterBlock cacheKeyFilter; 177 | 178 | /** 179 | * Returns global CMSDWebImageManager instance. 180 | * 181 | * @return CMSDWebImageManager shared instance 182 | */ 183 | + (CMSDWebImageManager *)sharedManager; 184 | 185 | /** 186 | * Downloads the image at the given URL if not present in cache or return the cached version otherwise. 187 | * 188 | * @param url The URL to the image 189 | * @param options A mask to specify options to use for this request 190 | * @param progressBlock A block called while image is downloading 191 | * @param completedBlock A block called when operation has been completed. 192 | * 193 | * This parameter is required. 194 | * 195 | * This block has no return value and takes the requested UIImage as first parameter. 196 | * In case of error the image parameter is nil and the second parameter may contain an NSError. 197 | * 198 | * The third parameter is an `CMSDImageCacheType` enum indicating if the image was retrieved from the local cache 199 | * or from the memory cache or from the network. 200 | * 201 | * The last parameter is set to NO when the CMSDWebImageProgressiveDownload option is used and the image is 202 | * downloading. This block is thus called repeatedly with a partial image. When image is fully downloaded, the 203 | * block is called a last time with the full image and the last parameter set to YES. 204 | * 205 | * @return Returns an NSObject conforming to CMSDWebImageOperation. Should be an instance of CMSDWebImageDownloaderOperation 206 | */ 207 | - (id )downloadImageWithURL:(NSURL *)url 208 | options:(CMSDWebImageOptions)options 209 | progress:(CMSDWebImageDownloaderProgressBlock)progressBlock 210 | completed:(CMSDWebImageCompletionWithFinishedBlock)completedBlock; 211 | 212 | /** 213 | * Saves image to cache for given URL 214 | * 215 | * @param image The image to cache 216 | * @param url The URL to the image 217 | * 218 | */ 219 | 220 | - (void)saveImageToCache:(UIImage *)image forURL:(NSURL *)url; 221 | 222 | /** 223 | * Cancel all current operations 224 | */ 225 | - (void)cancelAll; 226 | 227 | /** 228 | * Check one or more operations running 229 | */ 230 | - (BOOL)isRunning; 231 | 232 | /** 233 | * Check if image has already been cached 234 | * 235 | * @param url image url 236 | * 237 | * @return if the image was already cached 238 | */ 239 | - (BOOL)cachedImageExistsForURL:(NSURL *)url; 240 | 241 | /** 242 | * Check if image has already been cached on disk only 243 | * 244 | * @param url image url 245 | * 246 | * @return if the image was already cached (disk only) 247 | */ 248 | - (BOOL)diskImageExistsForURL:(NSURL *)url; 249 | 250 | /** 251 | * Async check if image has already been cached 252 | * 253 | * @param url image url 254 | * @param completionBlock the block to be executed when the check is finished 255 | * 256 | * @note the completion block is always executed on the main queue 257 | */ 258 | - (void)cachedImageExistsForURL:(NSURL *)url 259 | completion:(CMSDWebImageCheckCacheCompletionBlock)completionBlock; 260 | 261 | /** 262 | * Async check if image has already been cached on disk only 263 | * 264 | * @param url image url 265 | * @param completionBlock the block to be executed when the check is finished 266 | * 267 | * @note the completion block is always executed on the main queue 268 | */ 269 | - (void)diskImageExistsForURL:(NSURL *)url 270 | completion:(CMSDWebImageCheckCacheCompletionBlock)completionBlock; 271 | 272 | 273 | /** 274 | *Return the cache key for a given URL 275 | */ 276 | - (NSString *)cacheKeyForURL:(NSURL *)url; 277 | 278 | @end 279 | 280 | 281 | #pragma mark - Deprecated 282 | 283 | typedef void(^CMSDWebImageCompletedBlock)(UIImage *image, NSError *error, CMSDImageCacheType cacheType) __deprecated_msg("Block type deprecated. Use `CMSDWebImageCompletionBlock`"); 284 | typedef void(^CMSDWebImageCompletedWithFinishedBlock)(UIImage *image, NSError *error, CMSDImageCacheType cacheType, BOOL finished) __deprecated_msg("Block type deprecated. Use `CMSDWebImageCompletionWithFinishedBlock`"); 285 | 286 | 287 | @interface CMSDWebImageManager (Deprecated) 288 | 289 | /** 290 | * Downloads the image at the given URL if not present in cache or return the cached version otherwise. 291 | * 292 | * @deprecated This method has been deprecated. Use `downloadImageWithURL:options:progress:completed:` 293 | */ 294 | - (id )downloadWithURL:(NSURL *)url 295 | options:(CMSDWebImageOptions)options 296 | progress:(CMSDWebImageDownloaderProgressBlock)progressBlock 297 | completed:(CMSDWebImageCompletedWithFinishedBlock)completedBlock __deprecated_msg("Method deprecated. Use `downloadImageWithURL:options:progress:completed:`"); 298 | 299 | @end 300 | -------------------------------------------------------------------------------- /MXScrollView/CMSDWebImage/CMSDWebImageOperation.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 CMSDWebImageOperation 12 | 13 | - (void)cancel; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /MXScrollView/CMSDWebImage/CMSDWebImagePrefetcher.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CMSDWebImage 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 "CMSDWebImageManager.h" 11 | 12 | @class CMSDWebImagePrefetcher; 13 | 14 | @protocol CMSDWebImagePrefetcherDelegate 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:(CMSDWebImagePrefetcher *)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:(CMSDWebImagePrefetcher *)imagePrefetcher didFinishWithTotalCount:(NSUInteger)totalCount skippedCount:(NSUInteger)skippedCount; 35 | 36 | @end 37 | 38 | typedef void(^CMSDWebImagePrefetcherProgressBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfTotalUrls); 39 | typedef void(^CMSDWebImagePrefetcherCompletionBlock)(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 CMSDWebImagePrefetcher : NSObject 45 | 46 | /** 47 | * The web image manager 48 | */ 49 | @property (strong, nonatomic, readonly) CMSDWebImageManager *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 | * CMSDWebImageOptions for prefetcher. Defaults to CMSDWebImageLowPriority. 58 | */ 59 | @property (nonatomic, assign) CMSDWebImageOptions 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 | + (CMSDWebImagePrefetcher *)sharedImagePrefetcher; 72 | 73 | /** 74 | * Allows you to instantiate a prefetcher with any arbitrary image manager. 75 | */ 76 | - (id)initWithImageManager:(CMSDWebImageManager *)manager; 77 | 78 | /** 79 | * Assign list of URLs to let CMSDWebImagePrefetcher 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 CMSDWebImagePrefetcher 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:(CMSDWebImagePrefetcherProgressBlock)progressBlock completed:(CMSDWebImagePrefetcherCompletionBlock)completionBlock; 101 | 102 | /** 103 | * Remove and cancel queued list 104 | */ 105 | - (void)cancelPrefetching; 106 | 107 | 108 | @end 109 | -------------------------------------------------------------------------------- /MXScrollView/CMSDWebImage/CMSDWebImagePrefetcher.m: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CMSDWebImage 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 "CMSDWebImagePrefetcher.h" 10 | 11 | @interface CMSDWebImagePrefetcher () 12 | 13 | @property (strong, nonatomic) CMSDWebImageManager *manager; 14 | @property (strong, nonatomic) NSArray *prefetchURLs; 15 | @property (assign, nonatomic) NSUInteger requestedCount; 16 | @property (assign, nonatomic) NSUInteger skippedCount; 17 | @property (assign, nonatomic) NSUInteger finishedCount; 18 | @property (assign, nonatomic) NSTimeInterval startedTime; 19 | @property (copy, nonatomic) CMSDWebImagePrefetcherCompletionBlock completionBlock; 20 | @property (copy, nonatomic) CMSDWebImagePrefetcherProgressBlock progressBlock; 21 | 22 | @end 23 | 24 | @implementation CMSDWebImagePrefetcher 25 | 26 | + (CMSDWebImagePrefetcher *)sharedImagePrefetcher { 27 | static dispatch_once_t once; 28 | static id instance; 29 | dispatch_once(&once, ^{ 30 | instance = [self new]; 31 | }); 32 | return instance; 33 | } 34 | 35 | - (id)init { 36 | return [self initWithImageManager:[CMSDWebImageManager new]]; 37 | } 38 | 39 | - (id)initWithImageManager:(CMSDWebImageManager *)manager { 40 | if ((self = [super init])) { 41 | _manager = manager; 42 | _options = CMSDWebImageLowPriority; 43 | _prefetcherQueue = dispatch_get_main_queue(); 44 | self.maxConcurrentDownloads = 3; 45 | } 46 | return self; 47 | } 48 | 49 | - (void)setMaxConcurrentDownloads:(NSUInteger)maxConcurrentDownloads { 50 | self.manager.imageDownloader.maxConcurrentDownloads = maxConcurrentDownloads; 51 | } 52 | 53 | - (NSUInteger)maxConcurrentDownloads { 54 | return self.manager.imageDownloader.maxConcurrentDownloads; 55 | } 56 | 57 | - (void)startPrefetchingAtIndex:(NSUInteger)index { 58 | if (index >= self.prefetchURLs.count) return; 59 | self.requestedCount++; 60 | [self.manager downloadImageWithURL:self.prefetchURLs[index] options:self.options progress:nil completed:^(UIImage *image, NSError *error, CMSDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { 61 | if (!finished) return; 62 | self.finishedCount++; 63 | 64 | if (image) { 65 | if (self.progressBlock) { 66 | self.progressBlock(self.finishedCount,[self.prefetchURLs count]); 67 | } 68 | } 69 | else { 70 | if (self.progressBlock) { 71 | self.progressBlock(self.finishedCount,[self.prefetchURLs count]); 72 | } 73 | // Add last failed 74 | self.skippedCount++; 75 | } 76 | if ([self.delegate respondsToSelector:@selector(imagePrefetcher:didPrefetchURL:finishedCount:totalCount:)]) { 77 | [self.delegate imagePrefetcher:self 78 | didPrefetchURL:self.prefetchURLs[index] 79 | finishedCount:self.finishedCount 80 | totalCount:self.prefetchURLs.count 81 | ]; 82 | } 83 | if (self.prefetchURLs.count > self.requestedCount) { 84 | dispatch_async(self.prefetcherQueue, ^{ 85 | [self startPrefetchingAtIndex:self.requestedCount]; 86 | }); 87 | } else if (self.finishedCount == self.requestedCount) { 88 | [self reportStatus]; 89 | if (self.completionBlock) { 90 | self.completionBlock(self.finishedCount, self.skippedCount); 91 | self.completionBlock = nil; 92 | } 93 | self.progressBlock = nil; 94 | } 95 | }]; 96 | } 97 | 98 | - (void)reportStatus { 99 | NSUInteger total = [self.prefetchURLs count]; 100 | if ([self.delegate respondsToSelector:@selector(imagePrefetcher:didFinishWithTotalCount:skippedCount:)]) { 101 | [self.delegate imagePrefetcher:self 102 | didFinishWithTotalCount:(total - self.skippedCount) 103 | skippedCount:self.skippedCount 104 | ]; 105 | } 106 | } 107 | 108 | - (void)prefetchURLs:(NSArray *)urls { 109 | [self prefetchURLs:urls progress:nil completed:nil]; 110 | } 111 | 112 | - (void)prefetchURLs:(NSArray *)urls progress:(CMSDWebImagePrefetcherProgressBlock)progressBlock completed:(CMSDWebImagePrefetcherCompletionBlock)completionBlock { 113 | [self cancelPrefetching]; // Prevent duplicate prefetch request 114 | self.startedTime = CFAbsoluteTimeGetCurrent(); 115 | self.prefetchURLs = urls; 116 | self.completionBlock = completionBlock; 117 | self.progressBlock = progressBlock; 118 | 119 | if (urls.count == 0) { 120 | if (completionBlock) { 121 | completionBlock(0,0); 122 | } 123 | } else { 124 | // Starts prefetching from the very first image on the list with the max allowed concurrency 125 | NSUInteger listCount = self.prefetchURLs.count; 126 | for (NSUInteger i = 0; i < self.maxConcurrentDownloads && self.requestedCount < listCount; i++) { 127 | [self startPrefetchingAtIndex:i]; 128 | } 129 | } 130 | } 131 | 132 | - (void)cancelPrefetching { 133 | self.prefetchURLs = nil; 134 | self.skippedCount = 0; 135 | self.requestedCount = 0; 136 | self.finishedCount = 0; 137 | [self.manager cancelAll]; 138 | } 139 | 140 | @end 141 | -------------------------------------------------------------------------------- /MXScrollView/CMSDWebImage/MKAnnotationView+CMWebCache.h: -------------------------------------------------------------------------------- 1 | // 2 | // MKAnnotationView+WebCache.h 3 | // CMSDWebImage 4 | // 5 | // Created by Olivier Poitrey on 14/03/12. 6 | // Copyright (c) 2012 Dailymotion. All rights reserved. 7 | // 8 | 9 | #import "MapKit/MapKit.h" 10 | #import "CMSDWebImageManager.h" 11 | 12 | /** 13 | * Integrates CMSDWebImage async downloading and caching of remote images with MKAnnotationView. 14 | */ 15 | @interface MKAnnotationView (CMWebCache) 16 | 17 | /** 18 | * Get the current image URL. 19 | * 20 | * Note that because of the limitations of categories this property can get out of sync 21 | * if you use CMSD_setImage: directly. 22 | */ 23 | - (NSURL *)CMSD_imageURL; 24 | 25 | /** 26 | * Set the imageView `image` with an `url`. 27 | * 28 | * The download is asynchronous and cached. 29 | * 30 | * @param url The url for the image. 31 | */ 32 | - (void)CMSD_setImageWithURL:(NSURL *)url; 33 | 34 | /** 35 | * Set the imageView `image` with an `url` and a placeholder. 36 | * 37 | * The download is asynchronous and cached. 38 | * 39 | * @param url The url for the image. 40 | * @param placeholder The image to be set initially, until the image request finishes. 41 | * @see CMSD_setImageWithURL:placeholderImage:options: 42 | */ 43 | - (void)CMSD_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder; 44 | 45 | /** 46 | * Set the imageView `image` with an `url`, placeholder and custom options. 47 | * 48 | * The download is asynchronous and cached. 49 | * 50 | * @param url The url for the image. 51 | * @param placeholder The image to be set initially, until the image request finishes. 52 | * @param options The options to use when downloading the image. @see CMSDWebImageOptions for the possible values. 53 | */ 54 | 55 | - (void)CMSD_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(CMSDWebImageOptions)options; 56 | 57 | /** 58 | * Set the imageView `image` with an `url`. 59 | * 60 | * The download is asynchronous and cached. 61 | * 62 | * @param url The url for the image. 63 | * @param completedBlock A block called when operation has been completed. This block has no return value 64 | * and takes the requested UIImage as first parameter. In case of error the image parameter 65 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 66 | * indicating if the image was retrieved from the local cache or from the network. 67 | * The fourth parameter is the original image url. 68 | */ 69 | - (void)CMSD_setImageWithURL:(NSURL *)url completed:(CMSDWebImageCompletionBlock)completedBlock; 70 | 71 | /** 72 | * Set the imageView `image` with an `url`, placeholder. 73 | * 74 | * The download is asynchronous and cached. 75 | * 76 | * @param url The url for the image. 77 | * @param placeholder The image to be set initially, until the image request finishes. 78 | * @param completedBlock A block called when operation has been completed. This block has no return value 79 | * and takes the requested UIImage as first parameter. In case of error the image parameter 80 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 81 | * indicating if the image was retrieved from the local cache or from the network. 82 | * The fourth parameter is the original image url. 83 | */ 84 | - (void)CMSD_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(CMSDWebImageCompletionBlock)completedBlock; 85 | 86 | /** 87 | * Set the imageView `image` with an `url`, placeholder and custom options. 88 | * 89 | * The download is asynchronous and cached. 90 | * 91 | * @param url The url for the image. 92 | * @param placeholder The image to be set initially, until the image request finishes. 93 | * @param options The options to use when downloading the image. @see CMSDWebImageOptions for the possible values. 94 | * @param completedBlock A block called when operation has been completed. This block has no return value 95 | * and takes the requested UIImage as first parameter. In case of error the image parameter 96 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 97 | * indicating if the image was retrieved from the local cache or from the network. 98 | * The fourth parameter is the original image url. 99 | */ 100 | - (void)CMSD_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(CMSDWebImageOptions)options completed:(CMSDWebImageCompletionBlock)completedBlock; 101 | 102 | /** 103 | * Cancel the current download 104 | */ 105 | - (void)CMSD_cancelCurrentImageLoad; 106 | 107 | @end 108 | 109 | 110 | @interface MKAnnotationView (WebCacheDeprecated) 111 | 112 | - (NSURL *)imageURL __deprecated_msg("Use `CMSD_imageURL`"); 113 | 114 | - (void)setImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `CMSD_setImageWithURL:`"); 115 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `CMSD_setImageWithURL:placeholderImage:`"); 116 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(CMSDWebImageOptions)options __deprecated_msg("Method deprecated. Use `CMSD_setImageWithURL:placeholderImage:options:`"); 117 | 118 | - (void)setImageWithURL:(NSURL *)url completed:(CMSDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `CMSD_setImageWithURL:completed:`"); 119 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(CMSDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `CMSD_setImageWithURL:placeholderImage:completed:`"); 120 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(CMSDWebImageOptions)options completed:(CMSDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `CMSD_setImageWithURL:placeholderImage:options:completed:`"); 121 | 122 | - (void)cancelCurrentImageLoad __deprecated_msg("Use `CMSD_cancelCurrentImageLoad`"); 123 | 124 | @end 125 | -------------------------------------------------------------------------------- /MXScrollView/CMSDWebImage/MKAnnotationView+CMWebCache.m: -------------------------------------------------------------------------------- 1 | // 2 | // MKAnnotationView+WebCache.m 3 | // CMSDWebImage 4 | // 5 | // Created by Olivier Poitrey on 14/03/12. 6 | // Copyright (c) 2012 Dailymotion. All rights reserved. 7 | // 8 | 9 | #import "MKAnnotationView+CMWebCache.h" 10 | #import "objc/runtime.h" 11 | #import "UIView+CMWebCacheOperation.h" 12 | 13 | static char imageURLKey; 14 | 15 | @implementation MKAnnotationView (CMWebCache) 16 | 17 | - (NSURL *)CMSD_imageURL { 18 | return objc_getAssociatedObject(self, &imageURLKey); 19 | } 20 | 21 | - (void)CMSD_setImageWithURL:(NSURL *)url { 22 | [self CMSD_setImageWithURL:url placeholderImage:nil options:0 completed:nil]; 23 | } 24 | 25 | - (void)CMSD_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder { 26 | [self CMSD_setImageWithURL:url placeholderImage:placeholder options:0 completed:nil]; 27 | } 28 | 29 | - (void)CMSD_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(CMSDWebImageOptions)options { 30 | [self CMSD_setImageWithURL:url placeholderImage:placeholder options:options completed:nil]; 31 | } 32 | 33 | - (void)CMSD_setImageWithURL:(NSURL *)url completed:(CMSDWebImageCompletionBlock)completedBlock { 34 | [self CMSD_setImageWithURL:url placeholderImage:nil options:0 completed:completedBlock]; 35 | } 36 | 37 | - (void)CMSD_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(CMSDWebImageCompletionBlock)completedBlock { 38 | [self CMSD_setImageWithURL:url placeholderImage:placeholder options:0 completed:completedBlock]; 39 | } 40 | 41 | - (void)CMSD_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(CMSDWebImageOptions)options completed:(CMSDWebImageCompletionBlock)completedBlock { 42 | [self CMSD_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 = [CMSDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, CMSDImageCacheType 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 CMSD_setImageLoadOperation:operation forKey:@"MKAnnotationViewImage"]; 63 | } else { 64 | dispatch_main_async_safe(^{ 65 | NSError *error = [NSError errorWithDomain:CMSDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; 66 | if (completedBlock) { 67 | completedBlock(nil, error, CMSDImageCacheTypeNone, url); 68 | } 69 | }); 70 | } 71 | } 72 | 73 | - (void)CMSD_cancelCurrentImageLoad { 74 | [self CMSD_cancelImageLoadOperationWithKey:@"MKAnnotationViewImage"]; 75 | } 76 | 77 | @end 78 | 79 | 80 | @implementation MKAnnotationView (WebCacheDeprecated) 81 | 82 | - (NSURL *)imageURL { 83 | return [self CMSD_imageURL]; 84 | } 85 | 86 | - (void)setImageWithURL:(NSURL *)url { 87 | [self CMSD_setImageWithURL:url placeholderImage:nil options:0 completed:nil]; 88 | } 89 | 90 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder { 91 | [self CMSD_setImageWithURL:url placeholderImage:placeholder options:0 completed:nil]; 92 | } 93 | 94 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(CMSDWebImageOptions)options { 95 | [self CMSD_setImageWithURL:url placeholderImage:placeholder options:options completed:nil]; 96 | } 97 | 98 | - (void)setImageWithURL:(NSURL *)url completed:(CMSDWebImageCompletedBlock)completedBlock { 99 | [self CMSD_setImageWithURL:url placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, CMSDImageCacheType cacheType, NSURL *imageURL) { 100 | if (completedBlock) { 101 | completedBlock(image, error, cacheType); 102 | } 103 | }]; 104 | } 105 | 106 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(CMSDWebImageCompletedBlock)completedBlock { 107 | [self CMSD_setImageWithURL:url placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, CMSDImageCacheType cacheType, NSURL *imageURL) { 108 | if (completedBlock) { 109 | completedBlock(image, error, cacheType); 110 | } 111 | }]; 112 | } 113 | 114 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(CMSDWebImageOptions)options completed:(CMSDWebImageCompletedBlock)completedBlock { 115 | [self CMSD_setImageWithURL:url placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, CMSDImageCacheType cacheType, NSURL *imageURL) { 116 | if (completedBlock) { 117 | completedBlock(image, error, cacheType); 118 | } 119 | }]; 120 | } 121 | 122 | - (void)cancelCurrentImageLoad { 123 | [self CMSD_cancelCurrentImageLoad]; 124 | } 125 | 126 | @end 127 | -------------------------------------------------------------------------------- /MXScrollView/CMSDWebImage/NSData+CMImageContentType.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 (CMImageContentType) 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 *)CMSD_contentTypeForImageData:(NSData *)data; 18 | 19 | @end 20 | 21 | 22 | @interface NSData (CMImageContentTypeDeprecated) 23 | 24 | + (NSString *)contentTypeForImageData:(NSData *)data __deprecated_msg("Use `sd_contentTypeForImageData:`"); 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /MXScrollView/CMSDWebImage/NSData+CMImageContentType.m: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Fabrice Aneche on 06/01/14. 3 | // Copyright (c) 2014 Dailymotion. All rights reserved. 4 | // 5 | 6 | #import "NSData+CMImageContentType.h" 7 | 8 | 9 | @implementation NSData (ImageContentType) 10 | 11 | + (NSString *)CMSD_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 CMSD_contentTypeForImageData:data]; 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /MXScrollView/CMSDWebImage/UIButton+CMWebCache.m: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CMSDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import "UIButton+CMWebCache.h" 10 | #import "objc/runtime.h" 11 | #import "UIView+CMWebCacheOperation.h" 12 | 13 | static char imageURLStorageKey; 14 | 15 | @implementation UIButton (WebCache) 16 | 17 | - (NSURL *)CMSD_currentImageURL { 18 | NSURL *url = self.imageURLStorage[@(self.state)]; 19 | 20 | if (!url) { 21 | url = self.imageURLStorage[@(UIControlStateNormal)]; 22 | } 23 | 24 | return url; 25 | } 26 | 27 | - (NSURL *)CMSD_imageURLForState:(UIControlState)state { 28 | return self.imageURLStorage[@(state)]; 29 | } 30 | 31 | - (void)CMSD_setImageWithURL:(NSURL *)url forState:(UIControlState)state { 32 | [self CMSD_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; 33 | } 34 | 35 | - (void)CMSD_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { 36 | [self CMSD_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; 37 | } 38 | 39 | - (void)CMSD_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(CMSDWebImageOptions)options { 40 | [self CMSD_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; 41 | } 42 | 43 | - (void)CMSD_setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(CMSDWebImageCompletionBlock)completedBlock { 44 | [self CMSD_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock]; 45 | } 46 | 47 | - (void)CMSD_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(CMSDWebImageCompletionBlock)completedBlock { 48 | [self CMSD_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock]; 49 | } 50 | 51 | - (void)CMSD_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(CMSDWebImageOptions)options completed:(CMSDWebImageCompletionBlock)completedBlock { 52 | 53 | [self setImage:placeholder forState:state]; 54 | [self CMSD_cancelImageLoadForState:state]; 55 | 56 | if (!url) { 57 | [self.imageURLStorage removeObjectForKey:@(state)]; 58 | 59 | dispatch_main_async_safe(^{ 60 | if (completedBlock) { 61 | NSError *error = [NSError errorWithDomain:CMSDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; 62 | completedBlock(nil, error, CMSDImageCacheTypeNone, url); 63 | } 64 | }); 65 | 66 | return; 67 | } 68 | 69 | self.imageURLStorage[@(state)] = url; 70 | 71 | __weak __typeof(self)wself = self; 72 | id operation = [CMSDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, CMSDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { 73 | if (!wself) return; 74 | dispatch_main_sync_safe(^{ 75 | __strong UIButton *sself = wself; 76 | if (!sself) return; 77 | if (image && (options & CMSDWebImageAvoidAutoSetImage) && completedBlock) 78 | { 79 | completedBlock(image, error, cacheType, url); 80 | return; 81 | } 82 | else if (image) { 83 | [sself setImage:image forState:state]; 84 | } 85 | if (completedBlock && finished) { 86 | completedBlock(image, error, cacheType, url); 87 | } 88 | }); 89 | }]; 90 | [self CMSD_setImageLoadOperation:operation forState:state]; 91 | } 92 | 93 | - (void)CMSD_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state { 94 | [self CMSD_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; 95 | } 96 | 97 | - (void)CMSD_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { 98 | [self CMSD_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; 99 | } 100 | 101 | - (void)CMSD_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(CMSDWebImageOptions)options { 102 | [self CMSD_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; 103 | } 104 | 105 | - (void)CMSD_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(CMSDWebImageCompletionBlock)completedBlock { 106 | [self CMSD_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock]; 107 | } 108 | 109 | - (void)CMSD_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(CMSDWebImageCompletionBlock)completedBlock { 110 | [self CMSD_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock]; 111 | } 112 | 113 | - (void)CMSD_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(CMSDWebImageOptions)options completed:(CMSDWebImageCompletionBlock)completedBlock { 114 | [self CMSD_cancelBackgroundImageLoadForState:state]; 115 | 116 | [self setBackgroundImage:placeholder forState:state]; 117 | 118 | if (url) { 119 | __weak __typeof(self)wself = self; 120 | id operation = [CMSDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, CMSDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { 121 | if (!wself) return; 122 | dispatch_main_sync_safe(^{ 123 | __strong UIButton *sself = wself; 124 | if (!sself) return; 125 | if (image && (options & CMSDWebImageAvoidAutoSetImage) && completedBlock) 126 | { 127 | completedBlock(image, error, cacheType, url); 128 | return; 129 | } 130 | else if (image) { 131 | [sself setBackgroundImage:image forState:state]; 132 | } 133 | if (completedBlock && finished) { 134 | completedBlock(image, error, cacheType, url); 135 | } 136 | }); 137 | }]; 138 | [self CMSD_setBackgroundImageLoadOperation:operation forState:state]; 139 | } else { 140 | dispatch_main_async_safe(^{ 141 | NSError *error = [NSError errorWithDomain:CMSDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; 142 | if (completedBlock) { 143 | completedBlock(nil, error, CMSDImageCacheTypeNone, url); 144 | } 145 | }); 146 | } 147 | } 148 | 149 | - (void)CMSD_setImageLoadOperation:(id)operation forState:(UIControlState)state { 150 | [self CMSD_setImageLoadOperation:operation forKey:[NSString stringWithFormat:@"UIButtonImageOperation%@", @(state)]]; 151 | } 152 | 153 | - (void)CMSD_cancelImageLoadForState:(UIControlState)state { 154 | [self CMSD_cancelImageLoadOperationWithKey:[NSString stringWithFormat:@"UIButtonImageOperation%@", @(state)]]; 155 | } 156 | 157 | - (void)CMSD_setBackgroundImageLoadOperation:(id)operation forState:(UIControlState)state { 158 | [self CMSD_setImageLoadOperation:operation forKey:[NSString stringWithFormat:@"UIButtonBackgroundImageOperation%@", @(state)]]; 159 | } 160 | 161 | - (void)CMSD_cancelBackgroundImageLoadForState:(UIControlState)state { 162 | [self CMSD_cancelImageLoadOperationWithKey:[NSString stringWithFormat:@"UIButtonBackgroundImageOperation%@", @(state)]]; 163 | } 164 | 165 | - (NSMutableDictionary *)imageURLStorage { 166 | NSMutableDictionary *storage = objc_getAssociatedObject(self, &imageURLStorageKey); 167 | if (!storage) 168 | { 169 | storage = [NSMutableDictionary dictionary]; 170 | objc_setAssociatedObject(self, &imageURLStorageKey, storage, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 171 | } 172 | 173 | return storage; 174 | } 175 | 176 | @end 177 | 178 | 179 | @implementation UIButton (WebCacheDeprecated) 180 | 181 | - (NSURL *)currentImageURL { 182 | return [self CMSD_currentImageURL]; 183 | } 184 | 185 | - (NSURL *)imageURLForState:(UIControlState)state { 186 | return [self CMSD_imageURLForState:state]; 187 | } 188 | 189 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state { 190 | [self CMSD_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; 191 | } 192 | 193 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { 194 | [self CMSD_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; 195 | } 196 | 197 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(CMSDWebImageOptions)options { 198 | [self CMSD_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; 199 | } 200 | 201 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(CMSDWebImageCompletedBlock)completedBlock { 202 | [self CMSD_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, CMSDImageCacheType cacheType, NSURL *imageURL) { 203 | if (completedBlock) { 204 | completedBlock(image, error, cacheType); 205 | } 206 | }]; 207 | } 208 | 209 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(CMSDWebImageCompletedBlock)completedBlock { 210 | [self CMSD_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, CMSDImageCacheType cacheType, NSURL *imageURL) { 211 | if (completedBlock) { 212 | completedBlock(image, error, cacheType); 213 | } 214 | }]; 215 | } 216 | 217 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(CMSDWebImageOptions)options completed:(CMSDWebImageCompletedBlock)completedBlock { 218 | [self CMSD_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, CMSDImageCacheType cacheType, NSURL *imageURL) { 219 | if (completedBlock) { 220 | completedBlock(image, error, cacheType); 221 | } 222 | }]; 223 | } 224 | 225 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state { 226 | [self CMSD_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil]; 227 | } 228 | 229 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder { 230 | [self CMSD_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil]; 231 | } 232 | 233 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(CMSDWebImageOptions)options { 234 | [self CMSD_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil]; 235 | } 236 | 237 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(CMSDWebImageCompletedBlock)completedBlock { 238 | [self CMSD_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, CMSDImageCacheType cacheType, NSURL *imageURL) { 239 | if (completedBlock) { 240 | completedBlock(image, error, cacheType); 241 | } 242 | }]; 243 | } 244 | 245 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(CMSDWebImageCompletedBlock)completedBlock { 246 | [self CMSD_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, CMSDImageCacheType cacheType, NSURL *imageURL) { 247 | if (completedBlock) { 248 | completedBlock(image, error, cacheType); 249 | } 250 | }]; 251 | } 252 | 253 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(CMSDWebImageOptions)options completed:(CMSDWebImageCompletedBlock)completedBlock { 254 | [self CMSD_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, CMSDImageCacheType cacheType, NSURL *imageURL) { 255 | if (completedBlock) { 256 | completedBlock(image, error, cacheType); 257 | } 258 | }]; 259 | } 260 | 261 | - (void)cancelCurrentImageLoad { 262 | // in a backwards compatible manner, cancel for current state 263 | [self CMSD_cancelImageLoadForState:self.state]; 264 | } 265 | 266 | - (void)cancelBackgroundImageLoadForState:(UIControlState)state { 267 | [self CMSD_cancelBackgroundImageLoadForState:state]; 268 | } 269 | 270 | @end 271 | -------------------------------------------------------------------------------- /MXScrollView/CMSDWebImage/UIImage+CMGIF.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 (CMGIF) 12 | 13 | + (UIImage *)CMSD_animatedGIFNamed:(NSString *)name; 14 | 15 | + (UIImage *)CMSD_animatedGIFWithData:(NSData *)data; 16 | 17 | - (UIImage *)CMSD_animatedImageByScalingAndCroppingToSize:(CGSize)size; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /MXScrollView/CMSDWebImage/UIImage+CMGIF.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+GIF.m 3 | // LBGIFImage 4 | // 5 | // Created by Laurin Brandner on 06.01.12. 6 | // Copyright (c) 2012 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import "UIImage+CMGIF.h" 10 | #import 11 | 12 | @implementation UIImage (GIF) 13 | 14 | + (UIImage *)CMSD_animatedGIFWithData:(NSData *)data { 15 | if (!data) { 16 | return nil; 17 | } 18 | 19 | CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL); 20 | 21 | size_t count = CGImageSourceGetCount(source); 22 | 23 | UIImage *animatedImage; 24 | 25 | if (count <= 1) { 26 | animatedImage = [[UIImage alloc] initWithData:data]; 27 | } 28 | else { 29 | NSMutableArray *images = [NSMutableArray array]; 30 | 31 | NSTimeInterval duration = 0.0f; 32 | 33 | for (size_t i = 0; i < count; i++) { 34 | CGImageRef image = CGImageSourceCreateImageAtIndex(source, i, NULL); 35 | if (!image) { 36 | continue; 37 | } 38 | 39 | duration += [self CMSD_frameDurationAtIndex:i source:source]; 40 | 41 | [images addObject:[UIImage imageWithCGImage:image scale:[UIScreen mainScreen].scale orientation:UIImageOrientationUp]]; 42 | 43 | CGImageRelease(image); 44 | } 45 | 46 | if (!duration) { 47 | duration = (1.0f / 10.0f) * count; 48 | } 49 | 50 | animatedImage = [UIImage animatedImageWithImages:images duration:duration]; 51 | } 52 | 53 | CFRelease(source); 54 | 55 | return animatedImage; 56 | } 57 | 58 | + (float)CMSD_frameDurationAtIndex:(NSUInteger)index source:(CGImageSourceRef)source { 59 | float frameDuration = 0.1f; 60 | CFDictionaryRef cfFrameProperties = CGImageSourceCopyPropertiesAtIndex(source, index, nil); 61 | NSDictionary *frameProperties = (__bridge NSDictionary *)cfFrameProperties; 62 | NSDictionary *gifProperties = frameProperties[(NSString *)kCGImagePropertyGIFDictionary]; 63 | 64 | NSNumber *delayTimeUnclampedProp = gifProperties[(NSString *)kCGImagePropertyGIFUnclampedDelayTime]; 65 | if (delayTimeUnclampedProp) { 66 | frameDuration = [delayTimeUnclampedProp floatValue]; 67 | } 68 | else { 69 | 70 | NSNumber *delayTimeProp = gifProperties[(NSString *)kCGImagePropertyGIFDelayTime]; 71 | if (delayTimeProp) { 72 | frameDuration = [delayTimeProp floatValue]; 73 | } 74 | } 75 | 76 | // Many annoying ads specify a 0 duration to make an image flash as quickly as possible. 77 | // We follow Firefox's behavior and use a duration of 100 ms for any frames that specify 78 | // a duration of <= 10 ms. See and 79 | // for more information. 80 | 81 | if (frameDuration < 0.011f) { 82 | frameDuration = 0.100f; 83 | } 84 | 85 | CFRelease(cfFrameProperties); 86 | return frameDuration; 87 | } 88 | 89 | + (UIImage *)CMSD_animatedGIFNamed:(NSString *)name { 90 | CGFloat scale = [UIScreen mainScreen].scale; 91 | 92 | if (scale > 1.0f) { 93 | NSString *retinaPath = [[NSBundle mainBundle] pathForResource:[name stringByAppendingString:@"@2x"] ofType:@"gif"]; 94 | 95 | NSData *data = [NSData dataWithContentsOfFile:retinaPath]; 96 | 97 | if (data) { 98 | return [UIImage CMSD_animatedGIFWithData:data]; 99 | } 100 | 101 | NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"gif"]; 102 | 103 | data = [NSData dataWithContentsOfFile:path]; 104 | 105 | if (data) { 106 | return [UIImage CMSD_animatedGIFWithData:data]; 107 | } 108 | 109 | return [UIImage imageNamed:name]; 110 | } 111 | else { 112 | NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"gif"]; 113 | 114 | NSData *data = [NSData dataWithContentsOfFile:path]; 115 | 116 | if (data) { 117 | return [UIImage CMSD_animatedGIFWithData:data]; 118 | } 119 | 120 | return [UIImage imageNamed:name]; 121 | } 122 | } 123 | 124 | - (UIImage *)CMSD_animatedImageByScalingAndCroppingToSize:(CGSize)size { 125 | if (CGSizeEqualToSize(self.size, size) || CGSizeEqualToSize(size, CGSizeZero)) { 126 | return self; 127 | } 128 | 129 | CGSize scaledSize = size; 130 | CGPoint thumbnailPoint = CGPointZero; 131 | 132 | CGFloat widthFactor = size.width / self.size.width; 133 | CGFloat heightFactor = size.height / self.size.height; 134 | CGFloat scaleFactor = (widthFactor > heightFactor) ? widthFactor : heightFactor; 135 | scaledSize.width = self.size.width * scaleFactor; 136 | scaledSize.height = self.size.height * scaleFactor; 137 | 138 | if (widthFactor > heightFactor) { 139 | thumbnailPoint.y = (size.height - scaledSize.height) * 0.5; 140 | } 141 | else if (widthFactor < heightFactor) { 142 | thumbnailPoint.x = (size.width - scaledSize.width) * 0.5; 143 | } 144 | 145 | NSMutableArray *scaledImages = [NSMutableArray array]; 146 | 147 | for (UIImage *image in self.images) { 148 | UIGraphicsBeginImageContextWithOptions(size, NO, 0.0); 149 | 150 | [image drawInRect:CGRectMake(thumbnailPoint.x, thumbnailPoint.y, scaledSize.width, scaledSize.height)]; 151 | UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 152 | 153 | [scaledImages addObject:newImage]; 154 | 155 | UIGraphicsEndImageContext(); 156 | } 157 | 158 | return [UIImage animatedImageWithImages:scaledImages duration:self.duration]; 159 | } 160 | 161 | @end 162 | -------------------------------------------------------------------------------- /MXScrollView/CMSDWebImage/UIImage+CMMultiFormat.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 (CMMultiFormat) 12 | 13 | + (UIImage *)CMSD_imageWithData:(NSData *)data; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /MXScrollView/CMSDWebImage/UIImage+CMMultiFormat.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+MultiFormat.m 3 | // CMSDWebImage 4 | // 5 | // Created by Olivier Poitrey on 07/06/13. 6 | // Copyright (c) 2013 Dailymotion. All rights reserved. 7 | // 8 | 9 | #import "UIImage+CMMultiFormat.h" 10 | #import "UIImage+CMGIF.h" 11 | #import "NSData+CMImageContentType.h" 12 | #import 13 | 14 | #ifdef CMSD_WEBP 15 | #import "UIImage+CMWebP.h" 16 | #endif 17 | 18 | @implementation UIImage (CMMultiFormat) 19 | 20 | + (UIImage *)CMSD_imageWithData:(NSData *)data { 21 | if (!data) { 22 | return nil; 23 | } 24 | 25 | UIImage *image; 26 | NSString *imageContentType = [NSData CMSD_contentTypeForImageData:data]; 27 | if ([imageContentType isEqualToString:@"image/gif"]) { 28 | image = [UIImage CMSD_animatedGIFWithData:data]; 29 | } 30 | #ifdef CMSD_WEBP 31 | else if ([imageContentType isEqualToString:@"image/webp"]) 32 | { 33 | image = [UIImage CMSD_imageWithWebPData:data]; 34 | } 35 | #endif 36 | else { 37 | image = [[UIImage alloc] initWithData:data]; 38 | UIImageOrientation orientation = [self CMSD_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)CMSD_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 CMSD_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) CMSD_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 | -------------------------------------------------------------------------------- /MXScrollView/CMSDWebImage/UIImage+CMWebP.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 *)CMSD_imageWithWebPData:(NSData *)data; 23 | 24 | @end 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /MXScrollView/CMSDWebImage/UIImage+CMWebP.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+WebP.m 3 | // CMSDWebImage 4 | // 5 | // Created by Olivier Poitrey on 07/06/13. 6 | // Copyright (c) 2013 Dailymotion. All rights reserved. 7 | // 8 | 9 | #ifdef CMSD_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 *)CMSD_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 | -------------------------------------------------------------------------------- /MXScrollView/CMSDWebImage/UIImageView+CMHighlightedWebCache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CMSDWebImage 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 "CMSDWebImageCompat.h" 11 | #import "CMSDWebImageManager.h" 12 | 13 | /** 14 | * Integrates CMSDWebImage async downloading and caching of remote images with UIImageView for highlighted state. 15 | */ 16 | @interface UIImageView (CMHighlightedWebCache) 17 | 18 | /** 19 | * Set the imageView `highlightedImage` with an `url`. 20 | * 21 | * The download is asynchronous and cached. 22 | * 23 | * @param url The url for the image. 24 | */ 25 | - (void)CMSD_setHighlightedImageWithURL:(NSURL *)url; 26 | 27 | /** 28 | * Set the imageView `highlightedImage` with an `url` and custom options. 29 | * 30 | * The download is asynchronous and cached. 31 | * 32 | * @param url The url for the image. 33 | * @param options The options to use when downloading the image. @see CMSDWebImageOptions for the possible values. 34 | */ 35 | - (void)CMSD_setHighlightedImageWithURL:(NSURL *)url options:(CMSDWebImageOptions)options; 36 | 37 | /** 38 | * Set the imageView `highlightedImage` with an `url`. 39 | * 40 | * The download is asynchronous and cached. 41 | * 42 | * @param url The url for the image. 43 | * @param completedBlock A block called when operation has been completed. This block has no return value 44 | * and takes the requested UIImage as first parameter. In case of error the image parameter 45 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 46 | * indicating if the image was retrieved from the local cache or from the network. 47 | * The fourth parameter is the original image url. 48 | */ 49 | - (void)CMSD_setHighlightedImageWithURL:(NSURL *)url completed:(CMSDWebImageCompletionBlock)completedBlock; 50 | 51 | /** 52 | * Set the imageView `highlightedImage` with an `url` and custom options. 53 | * 54 | * The download is asynchronous and cached. 55 | * 56 | * @param url The url for the image. 57 | * @param options The options to use when downloading the image. @see CMSDWebImageOptions for the possible values. 58 | * @param completedBlock A block called when operation has been completed. This block has no return value 59 | * and takes the requested UIImage as first parameter. In case of error the image parameter 60 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 61 | * indicating if the image was retrieved from the local cache or from the network. 62 | * The fourth parameter is the original image url. 63 | */ 64 | - (void)CMSD_setHighlightedImageWithURL:(NSURL *)url options:(CMSDWebImageOptions)options completed:(CMSDWebImageCompletionBlock)completedBlock; 65 | 66 | /** 67 | * Set the imageView `highlightedImage` with an `url` and custom options. 68 | * 69 | * The download is asynchronous and cached. 70 | * 71 | * @param url The url for the image. 72 | * @param options The options to use when downloading the image. @see CMSDWebImageOptions for the possible values. 73 | * @param progressBlock A block called while image is downloading 74 | * @param completedBlock A block called when operation has been completed. This block has no return value 75 | * and takes the requested UIImage as first parameter. In case of error the image parameter 76 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 77 | * indicating if the image was retrieved from the local cache or from the network. 78 | * The fourth parameter is the original image url. 79 | */ 80 | - (void)CMSD_setHighlightedImageWithURL:(NSURL *)url options:(CMSDWebImageOptions)options progress:(CMSDWebImageDownloaderProgressBlock)progressBlock completed:(CMSDWebImageCompletionBlock)completedBlock; 81 | 82 | /** 83 | * Cancel the current download 84 | */ 85 | - (void)CMSD_cancelCurrentHighlightedImageLoad; 86 | 87 | @end 88 | 89 | 90 | @interface UIImageView (HighlightedWebCacheDeprecated) 91 | 92 | - (void)setHighlightedImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `CMSD_setHighlightedImageWithURL:`"); 93 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(CMSDWebImageOptions)options __deprecated_msg("Method deprecated. Use `CMSD_setHighlightedImageWithURL:options:`"); 94 | - (void)setHighlightedImageWithURL:(NSURL *)url completed:(CMSDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `CMSD_setHighlightedImageWithURL:completed:`"); 95 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(CMSDWebImageOptions)options completed:(CMSDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `CMSD_setHighlightedImageWithURL:options:completed:`"); 96 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(CMSDWebImageOptions)options progress:(CMSDWebImageDownloaderProgressBlock)progressBlock completed:(CMSDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `CMSD_setHighlightedImageWithURL:options:progress:completed:`"); 97 | 98 | - (void)cancelCurrentHighlightedImageLoad __deprecated_msg("Use `CMSD_cancelCurrentHighlightedImageLoad`"); 99 | 100 | @end 101 | -------------------------------------------------------------------------------- /MXScrollView/CMSDWebImage/UIImageView+CMHighlightedWebCache.m: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CMSDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import "UIImageView+CMHighlightedWebCache.h" 10 | #import "UIView+CMWebCacheOperation.h" 11 | 12 | #define UIImageViewHighlightedWebCacheOperationKey @"highlightedImage" 13 | 14 | @implementation UIImageView (HighlightedWebCache) 15 | 16 | - (void)CMSD_setHighlightedImageWithURL:(NSURL *)url { 17 | [self CMSD_setHighlightedImageWithURL:url options:0 progress:nil completed:nil]; 18 | } 19 | 20 | - (void)CMSD_setHighlightedImageWithURL:(NSURL *)url options:(CMSDWebImageOptions)options { 21 | [self CMSD_setHighlightedImageWithURL:url options:options progress:nil completed:nil]; 22 | } 23 | 24 | - (void)CMSD_setHighlightedImageWithURL:(NSURL *)url completed:(CMSDWebImageCompletionBlock)completedBlock { 25 | [self CMSD_setHighlightedImageWithURL:url options:0 progress:nil completed:completedBlock]; 26 | } 27 | 28 | - (void)CMSD_setHighlightedImageWithURL:(NSURL *)url options:(CMSDWebImageOptions)options completed:(CMSDWebImageCompletionBlock)completedBlock { 29 | [self CMSD_setHighlightedImageWithURL:url options:options progress:nil completed:completedBlock]; 30 | } 31 | 32 | - (void)CMSD_setHighlightedImageWithURL:(NSURL *)url options:(CMSDWebImageOptions)options progress:(CMSDWebImageDownloaderProgressBlock)progressBlock completed:(CMSDWebImageCompletionBlock)completedBlock { 33 | [self CMSD_cancelCurrentHighlightedImageLoad]; 34 | 35 | if (url) { 36 | __weak __typeof(self)wself = self; 37 | id operation = [CMSDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, CMSDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { 38 | if (!wself) return; 39 | dispatch_main_sync_safe (^ 40 | { 41 | if (!wself) return; 42 | if (image && (options & CMSDWebImageAvoidAutoSetImage) && completedBlock) 43 | { 44 | completedBlock(image, error, cacheType, url); 45 | return; 46 | } 47 | else if (image) { 48 | wself.highlightedImage = image; 49 | [wself setNeedsLayout]; 50 | } 51 | if (completedBlock && finished) { 52 | completedBlock(image, error, cacheType, url); 53 | } 54 | }); 55 | }]; 56 | [self CMSD_setImageLoadOperation:operation forKey:UIImageViewHighlightedWebCacheOperationKey]; 57 | } else { 58 | dispatch_main_async_safe(^{ 59 | NSError *error = [NSError errorWithDomain:CMSDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; 60 | if (completedBlock) { 61 | completedBlock(nil, error, CMSDImageCacheTypeNone, url); 62 | } 63 | }); 64 | } 65 | } 66 | 67 | - (void)CMSD_cancelCurrentHighlightedImageLoad { 68 | [self CMSD_cancelImageLoadOperationWithKey:UIImageViewHighlightedWebCacheOperationKey]; 69 | } 70 | 71 | @end 72 | 73 | 74 | @implementation UIImageView (HighlightedWebCacheDeprecated) 75 | 76 | - (void)setHighlightedImageWithURL:(NSURL *)url { 77 | [self CMSD_setHighlightedImageWithURL:url options:0 progress:nil completed:nil]; 78 | } 79 | 80 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(CMSDWebImageOptions)options { 81 | [self CMSD_setHighlightedImageWithURL:url options:options progress:nil completed:nil]; 82 | } 83 | 84 | - (void)setHighlightedImageWithURL:(NSURL *)url completed:(CMSDWebImageCompletedBlock)completedBlock { 85 | [self CMSD_setHighlightedImageWithURL:url options:0 progress:nil completed:^(UIImage *image, NSError *error, CMSDImageCacheType cacheType, NSURL *imageURL) { 86 | if (completedBlock) { 87 | completedBlock(image, error, cacheType); 88 | } 89 | }]; 90 | } 91 | 92 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(CMSDWebImageOptions)options completed:(CMSDWebImageCompletedBlock)completedBlock { 93 | [self CMSD_setHighlightedImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, CMSDImageCacheType cacheType, NSURL *imageURL) { 94 | if (completedBlock) { 95 | completedBlock(image, error, cacheType); 96 | } 97 | }]; 98 | } 99 | 100 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(CMSDWebImageOptions)options progress:(CMSDWebImageDownloaderProgressBlock)progressBlock completed:(CMSDWebImageCompletedBlock)completedBlock { 101 | [self CMSD_setHighlightedImageWithURL:url options:0 progress:progressBlock completed:^(UIImage *image, NSError *error, CMSDImageCacheType cacheType, NSURL *imageURL) { 102 | if (completedBlock) { 103 | completedBlock(image, error, cacheType); 104 | } 105 | }]; 106 | } 107 | 108 | - (void)cancelCurrentHighlightedImageLoad { 109 | [self CMSD_cancelCurrentHighlightedImageLoad]; 110 | } 111 | 112 | @end 113 | -------------------------------------------------------------------------------- /MXScrollView/CMSDWebImage/UIImageView+CMWebCache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CMSDWebImage 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 "CMSDWebImageCompat.h" 10 | #import "CMSDWebImageManager.h" 11 | 12 | /** 13 | * Integrates CMSDWebImage async downloading and caching of remote images with UIImageView. 14 | * 15 | * Usage with a UITableViewCell sub-class: 16 | * 17 | * @code 18 | 19 | #import 20 | 21 | ... 22 | 23 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 24 | { 25 | static NSString *MyIdentifier = @"MyIdentifier"; 26 | 27 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 28 | 29 | if (cell == nil) { 30 | cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] 31 | autorelease]; 32 | } 33 | 34 | // Here we use the provided CMSD_setImageWithURL: method to load the web image 35 | // Ensure you use a placeholder image otherwise cells will be initialized with no image 36 | [cell.imageView CMSD_setImageWithURL:[NSURL URLWithString:@"http://example.com/image.jpg"] 37 | placeholderImage:[UIImage imageNamed:@"placeholder"]]; 38 | 39 | cell.textLabel.text = @"My Text"; 40 | return cell; 41 | } 42 | 43 | * @endcode 44 | */ 45 | @interface UIImageView (CMWebCache) 46 | 47 | /** 48 | * Get the current image URL. 49 | * 50 | * Note that because of the limitations of categories this property can get out of sync 51 | * if you use CMSD_setImage: directly. 52 | */ 53 | - (NSURL *)CMSD_imageURL; 54 | 55 | /** 56 | * Set the imageView `image` with an `url`. 57 | * 58 | * The download is asynchronous and cached. 59 | * 60 | * @param url The url for the image. 61 | */ 62 | - (void)CMSD_setImageWithURL:(NSURL *)url; 63 | 64 | /** 65 | * Set the imageView `image` with an `url` and a placeholder. 66 | * 67 | * The download is asynchronous and cached. 68 | * 69 | * @param url The url for the image. 70 | * @param placeholder The image to be set initially, until the image request finishes. 71 | * @see CMSD_setImageWithURL:placeholderImage:options: 72 | */ 73 | - (void)CMSD_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder; 74 | 75 | /** 76 | * Set the imageView `image` with an `url`, placeholder and custom options. 77 | * 78 | * The download is asynchronous and cached. 79 | * 80 | * @param url The url for the image. 81 | * @param placeholder The image to be set initially, until the image request finishes. 82 | * @param options The options to use when downloading the image. @see CMSDWebImageOptions for the possible values. 83 | */ 84 | - (void)CMSD_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(CMSDWebImageOptions)options; 85 | 86 | /** 87 | * Set the imageView `image` with an `url`. 88 | * 89 | * The download is asynchronous and cached. 90 | * 91 | * @param url The url for the image. 92 | * @param completedBlock A block called when operation has been completed. This block has no return value 93 | * and takes the requested UIImage as first parameter. In case of error the image parameter 94 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 95 | * indicating if the image was retrieved from the local cache or from the network. 96 | * The fourth parameter is the original image url. 97 | */ 98 | - (void)CMSD_setImageWithURL:(NSURL *)url completed:(CMSDWebImageCompletionBlock)completedBlock; 99 | 100 | /** 101 | * Set the imageView `image` with an `url`, placeholder. 102 | * 103 | * The download is asynchronous and cached. 104 | * 105 | * @param url The url for the image. 106 | * @param placeholder The image to be set initially, until the image request finishes. 107 | * @param completedBlock A block called when operation has been completed. This block has no return value 108 | * and takes the requested UIImage as first parameter. In case of error the image parameter 109 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 110 | * indicating if the image was retrieved from the local cache or from the network. 111 | * The fourth parameter is the original image url. 112 | */ 113 | - (void)CMSD_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(CMSDWebImageCompletionBlock)completedBlock; 114 | 115 | /** 116 | * Set the imageView `image` with an `url`, placeholder and custom options. 117 | * 118 | * The download is asynchronous and cached. 119 | * 120 | * @param url The url for the image. 121 | * @param placeholder The image to be set initially, until the image request finishes. 122 | * @param options The options to use when downloading the image. @see CMSDWebImageOptions for the possible values. 123 | * @param completedBlock A block called when operation has been completed. This block has no return value 124 | * and takes the requested UIImage as first parameter. In case of error the image parameter 125 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 126 | * indicating if the image was retrieved from the local cache or from the network. 127 | * The fourth parameter is the original image url. 128 | */ 129 | - (void)CMSD_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(CMSDWebImageOptions)options completed:(CMSDWebImageCompletionBlock)completedBlock; 130 | 131 | /** 132 | * Set the imageView `image` with an `url`, placeholder and custom options. 133 | * 134 | * The download is asynchronous and cached. 135 | * 136 | * @param url The url for the image. 137 | * @param placeholder The image to be set initially, until the image request finishes. 138 | * @param options The options to use when downloading the image. @see CMSDWebImageOptions for the possible values. 139 | * @param progressBlock A block called while image is downloading 140 | * @param completedBlock A block called when operation has been completed. This block has no return value 141 | * and takes the requested UIImage as first parameter. In case of error the image parameter 142 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 143 | * indicating if the image was retrieved from the local cache or from the network. 144 | * The fourth parameter is the original image url. 145 | */ 146 | - (void)CMSD_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(CMSDWebImageOptions)options progress:(CMSDWebImageDownloaderProgressBlock)progressBlock completed:(CMSDWebImageCompletionBlock)completedBlock; 147 | 148 | /** 149 | * Set the imageView `image` with an `url` and optionally a placeholder image. 150 | * 151 | * The download is asynchronous and cached. 152 | * 153 | * @param url The url for the image. 154 | * @param placeholder The image to be set initially, until the image request finishes. 155 | * @param options The options to use when downloading the image. @see CMSDWebImageOptions for the possible values. 156 | * @param progressBlock A block called while image is downloading 157 | * @param completedBlock A block called when operation has been completed. This block has no return value 158 | * and takes the requested UIImage as first parameter. In case of error the image parameter 159 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean 160 | * indicating if the image was retrieved from the local cache or from the network. 161 | * The fourth parameter is the original image url. 162 | */ 163 | - (void)CMSD_setImageWithPreviousCachedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(CMSDWebImageOptions)options progress:(CMSDWebImageDownloaderProgressBlock)progressBlock completed:(CMSDWebImageCompletionBlock)completedBlock; 164 | 165 | /** 166 | * Download an array of images and starts them in an animation loop 167 | * 168 | * @param arrayOfURLs An array of NSURL 169 | */ 170 | - (void)CMSD_setAnimationImagesWithURLs:(NSArray *)arrayOfURLs; 171 | 172 | /** 173 | * Cancel the current download 174 | */ 175 | - (void)CMSD_cancelCurrentImageLoad; 176 | 177 | - (void)CMSD_cancelCurrentAnimationImagesLoad; 178 | 179 | /** 180 | * Show activity UIActivityIndicatorView 181 | */ 182 | - (void)setShowActivityIndicatorView:(BOOL)show; 183 | 184 | /** 185 | * set desired UIActivityIndicatorViewStyle 186 | * 187 | * @param style The style of the UIActivityIndicatorView 188 | */ 189 | - (void)setIndicatorStyle:(UIActivityIndicatorViewStyle)style; 190 | 191 | @end 192 | 193 | 194 | @interface UIImageView (WebCacheDeprecated) 195 | 196 | - (NSURL *)imageURL __deprecated_msg("Use `CMSD_imageURL`"); 197 | 198 | - (void)setImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `CMSD_setImageWithURL:`"); 199 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `CMSD_setImageWithURL:placeholderImage:`"); 200 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(CMSDWebImageOptions)options __deprecated_msg("Method deprecated. Use `CMSD_setImageWithURL:placeholderImage:options`"); 201 | 202 | - (void)setImageWithURL:(NSURL *)url completed:(CMSDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `CMSD_setImageWithURL:completed:`"); 203 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(CMSDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `CMSD_setImageWithURL:placeholderImage:completed:`"); 204 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(CMSDWebImageOptions)options completed:(CMSDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `CMSD_setImageWithURL:placeholderImage:options:completed:`"); 205 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(CMSDWebImageOptions)options progress:(CMSDWebImageDownloaderProgressBlock)progressBlock completed:(CMSDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `CMSD_setImageWithURL:placeholderImage:options:progress:completed:`"); 206 | 207 | - (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs __deprecated_msg("Use `CMSD_setAnimationImagesWithURLs:`"); 208 | 209 | - (void)cancelCurrentArrayLoad __deprecated_msg("Use `CMSD_cancelCurrentAnimationImagesLoad`"); 210 | 211 | - (void)cancelCurrentImageLoad __deprecated_msg("Use `CMSD_cancelCurrentImageLoad`"); 212 | 213 | @end 214 | -------------------------------------------------------------------------------- /MXScrollView/CMSDWebImage/UIImageView+CMWebCache.m: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CMSDWebImage package. 3 | * (c) Olivier Poitrey 4 | * 5 | * For the full copyright and license information, please view the LICENSE 6 | * file that was distributed with this source code. 7 | */ 8 | 9 | #import "UIImageView+CMWebCache.h" 10 | #import "objc/runtime.h" 11 | #import "UIView+CMWebCacheOperation.h" 12 | 13 | static char imageURLKey; 14 | static char TAG_ACTIVITY_INDICATOR; 15 | static char TAG_ACTIVITY_STYLE; 16 | static char TAG_ACTIVITY_SHOW; 17 | 18 | @implementation UIImageView (WebCache) 19 | 20 | - (void)CMSD_setImageWithURL:(NSURL *)url { 21 | [self CMSD_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil]; 22 | } 23 | 24 | - (void)CMSD_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder { 25 | [self CMSD_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil]; 26 | } 27 | 28 | - (void)CMSD_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(CMSDWebImageOptions)options { 29 | [self CMSD_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil]; 30 | } 31 | 32 | - (void)CMSD_setImageWithURL:(NSURL *)url completed:(CMSDWebImageCompletionBlock)completedBlock { 33 | [self CMSD_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:completedBlock]; 34 | } 35 | 36 | - (void)CMSD_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(CMSDWebImageCompletionBlock)completedBlock { 37 | [self CMSD_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:completedBlock]; 38 | } 39 | 40 | - (void)CMSD_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(CMSDWebImageOptions)options completed:(CMSDWebImageCompletionBlock)completedBlock { 41 | [self CMSD_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:completedBlock]; 42 | } 43 | 44 | - (void)CMSD_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(CMSDWebImageOptions)options progress:(CMSDWebImageDownloaderProgressBlock)progressBlock completed:(CMSDWebImageCompletionBlock)completedBlock { 45 | [self CMSD_cancelCurrentImageLoad]; 46 | objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 47 | 48 | if (!(options & CMSDWebImageDelayPlaceholder)) { 49 | dispatch_main_async_safe(^{ 50 | self.image = placeholder; 51 | }); 52 | } 53 | 54 | if (url) { 55 | 56 | // check if activityView is enabled or not 57 | if ([self showActivityIndicatorView]) { 58 | [self addActivityIndicator]; 59 | } 60 | 61 | __weak __typeof(self)wself = self; 62 | id operation = [CMSDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, CMSDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { 63 | [wself removeActivityIndicator]; 64 | if (!wself) return; 65 | dispatch_main_sync_safe(^{ 66 | if (!wself) return; 67 | if (image && (options & CMSDWebImageAvoidAutoSetImage) && completedBlock) 68 | { 69 | completedBlock(image, error, cacheType, url); 70 | return; 71 | } 72 | else if (image) { 73 | wself.image = image; 74 | [wself setNeedsLayout]; 75 | } else { 76 | if ((options & CMSDWebImageDelayPlaceholder)) { 77 | wself.image = placeholder; 78 | [wself setNeedsLayout]; 79 | } 80 | } 81 | if (completedBlock && finished) { 82 | completedBlock(image, error, cacheType, url); 83 | } 84 | }); 85 | }]; 86 | [self CMSD_setImageLoadOperation:operation forKey:@"UIImageViewImageLoad"]; 87 | } else { 88 | dispatch_main_async_safe(^{ 89 | [self removeActivityIndicator]; 90 | if (completedBlock) { 91 | NSError *error = [NSError errorWithDomain:CMSDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}]; 92 | completedBlock(nil, error, CMSDImageCacheTypeNone, url); 93 | } 94 | }); 95 | } 96 | } 97 | 98 | - (void)CMSD_setImageWithPreviousCachedImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(CMSDWebImageOptions)options progress:(CMSDWebImageDownloaderProgressBlock)progressBlock completed:(CMSDWebImageCompletionBlock)completedBlock { 99 | NSString *key = [[CMSDWebImageManager sharedManager] cacheKeyForURL:url]; 100 | UIImage *lastPreviousCachedImage = [[CMSDImageCache sharedImageCache] imageFromDiskCacheForKey:key]; 101 | 102 | [self CMSD_setImageWithURL:url placeholderImage:lastPreviousCachedImage ?: placeholder options:options progress:progressBlock completed:completedBlock]; 103 | } 104 | 105 | - (NSURL *)CMSD_imageURL { 106 | return objc_getAssociatedObject(self, &imageURLKey); 107 | } 108 | 109 | - (void)CMSD_setAnimationImagesWithURLs:(NSArray *)arrayOfURLs { 110 | [self CMSD_cancelCurrentAnimationImagesLoad]; 111 | __weak __typeof(self)wself = self; 112 | 113 | NSMutableArray *operationsArray = [[NSMutableArray alloc] init]; 114 | 115 | for (NSURL *logoImageURL in arrayOfURLs) { 116 | id operation = [CMSDWebImageManager.sharedManager downloadImageWithURL:logoImageURL options:0 progress:nil completed:^(UIImage *image, NSError *error, CMSDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { 117 | if (!wself) return; 118 | dispatch_main_sync_safe(^{ 119 | __strong UIImageView *sself = wself; 120 | [sself stopAnimating]; 121 | if (sself && image) { 122 | NSMutableArray *currentImages = [[sself animationImages] mutableCopy]; 123 | if (!currentImages) { 124 | currentImages = [[NSMutableArray alloc] init]; 125 | } 126 | [currentImages addObject:image]; 127 | 128 | sself.animationImages = currentImages; 129 | [sself setNeedsLayout]; 130 | } 131 | [sself startAnimating]; 132 | }); 133 | }]; 134 | [operationsArray addObject:operation]; 135 | } 136 | 137 | [self CMSD_setImageLoadOperation:[NSArray arrayWithArray:operationsArray] forKey:@"UIImageViewAnimationImages"]; 138 | } 139 | 140 | - (void)CMSD_cancelCurrentImageLoad { 141 | [self CMSD_cancelImageLoadOperationWithKey:@"UIImageViewImageLoad"]; 142 | } 143 | 144 | - (void)CMSD_cancelCurrentAnimationImagesLoad { 145 | [self CMSD_cancelImageLoadOperationWithKey:@"UIImageViewAnimationImages"]; 146 | } 147 | 148 | 149 | #pragma mark - 150 | - (UIActivityIndicatorView *)activityIndicator { 151 | return (UIActivityIndicatorView *)objc_getAssociatedObject(self, &TAG_ACTIVITY_INDICATOR); 152 | } 153 | 154 | - (void)setActivityIndicator:(UIActivityIndicatorView *)activityIndicator { 155 | objc_setAssociatedObject(self, &TAG_ACTIVITY_INDICATOR, activityIndicator, OBJC_ASSOCIATION_RETAIN); 156 | } 157 | 158 | - (void)setShowActivityIndicatorView:(BOOL)show{ 159 | objc_setAssociatedObject(self, &TAG_ACTIVITY_SHOW, [NSNumber numberWithBool:show], OBJC_ASSOCIATION_RETAIN); 160 | } 161 | 162 | - (BOOL)showActivityIndicatorView{ 163 | return [objc_getAssociatedObject(self, &TAG_ACTIVITY_SHOW) boolValue]; 164 | } 165 | 166 | - (void)setIndicatorStyle:(UIActivityIndicatorViewStyle)style{ 167 | objc_setAssociatedObject(self, &TAG_ACTIVITY_STYLE, [NSNumber numberWithInt:style], OBJC_ASSOCIATION_RETAIN); 168 | } 169 | 170 | - (int)getIndicatorStyle{ 171 | return [objc_getAssociatedObject(self, &TAG_ACTIVITY_STYLE) intValue]; 172 | } 173 | 174 | - (void)addActivityIndicator { 175 | if (!self.activityIndicator) { 176 | self.activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:[self getIndicatorStyle]]; 177 | self.activityIndicator.translatesAutoresizingMaskIntoConstraints = NO; 178 | 179 | dispatch_main_async_safe(^{ 180 | [self addSubview:self.activityIndicator]; 181 | 182 | [self addConstraint:[NSLayoutConstraint constraintWithItem:self.activityIndicator 183 | attribute:NSLayoutAttributeCenterX 184 | relatedBy:NSLayoutRelationEqual 185 | toItem:self 186 | attribute:NSLayoutAttributeCenterX 187 | multiplier:1.0 188 | constant:0.0]]; 189 | [self addConstraint:[NSLayoutConstraint constraintWithItem:self.activityIndicator 190 | attribute:NSLayoutAttributeCenterY 191 | relatedBy:NSLayoutRelationEqual 192 | toItem:self 193 | attribute:NSLayoutAttributeCenterY 194 | multiplier:1.0 195 | constant:0.0]]; 196 | }); 197 | } 198 | 199 | dispatch_main_async_safe(^{ 200 | [self.activityIndicator startAnimating]; 201 | }); 202 | 203 | } 204 | 205 | - (void)removeActivityIndicator { 206 | if (self.activityIndicator) { 207 | [self.activityIndicator removeFromSuperview]; 208 | self.activityIndicator = nil; 209 | } 210 | } 211 | 212 | @end 213 | 214 | 215 | @implementation UIImageView (WebCacheDeprecated) 216 | 217 | - (NSURL *)imageURL { 218 | return [self CMSD_imageURL]; 219 | } 220 | 221 | - (void)setImageWithURL:(NSURL *)url { 222 | [self CMSD_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil]; 223 | } 224 | 225 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder { 226 | [self CMSD_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil]; 227 | } 228 | 229 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(CMSDWebImageOptions)options { 230 | [self CMSD_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil]; 231 | } 232 | 233 | - (void)setImageWithURL:(NSURL *)url completed:(CMSDWebImageCompletedBlock)completedBlock { 234 | [self CMSD_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:^(UIImage *image, NSError *error, CMSDImageCacheType cacheType, NSURL *imageURL) { 235 | if (completedBlock) { 236 | completedBlock(image, error, cacheType); 237 | } 238 | }]; 239 | } 240 | 241 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(CMSDWebImageCompletedBlock)completedBlock { 242 | [self CMSD_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:^(UIImage *image, NSError *error, CMSDImageCacheType cacheType, NSURL *imageURL) { 243 | if (completedBlock) { 244 | completedBlock(image, error, cacheType); 245 | } 246 | }]; 247 | } 248 | 249 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(CMSDWebImageOptions)options completed:(CMSDWebImageCompletedBlock)completedBlock { 250 | [self CMSD_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:^(UIImage *image, NSError *error, CMSDImageCacheType cacheType, NSURL *imageURL) { 251 | if (completedBlock) { 252 | completedBlock(image, error, cacheType); 253 | } 254 | }]; 255 | } 256 | 257 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(CMSDWebImageOptions)options progress:(CMSDWebImageDownloaderProgressBlock)progressBlock completed:(CMSDWebImageCompletedBlock)completedBlock { 258 | [self CMSD_setImageWithURL:url placeholderImage:placeholder options:options progress:progressBlock completed:^(UIImage *image, NSError *error, CMSDImageCacheType cacheType, NSURL *imageURL) { 259 | if (completedBlock) { 260 | completedBlock(image, error, cacheType); 261 | } 262 | }]; 263 | } 264 | 265 | - (void)cancelCurrentArrayLoad { 266 | [self CMSD_cancelCurrentAnimationImagesLoad]; 267 | } 268 | 269 | - (void)cancelCurrentImageLoad { 270 | [self CMSD_cancelCurrentImageLoad]; 271 | } 272 | 273 | - (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs { 274 | [self CMSD_setAnimationImagesWithURLs:arrayOfURLs]; 275 | } 276 | 277 | @end 278 | -------------------------------------------------------------------------------- /MXScrollView/CMSDWebImage/UIView+CMWebCacheOperation.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CMSDWebImage 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 "CMSDWebImageManager.h" 11 | 12 | @interface UIView (CMWebCacheOperation) 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)CMSD_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)CMSD_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)CMSD_removeImageLoadOperationWithKey:(NSString *)key; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /MXScrollView/CMSDWebImage/UIView+CMWebCacheOperation.m: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the CMSDWebImage 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+CMWebCacheOperation.h" 10 | #import "objc/runtime.h" 11 | 12 | static char loadOperationKey; 13 | 14 | @implementation UIView (CMWebCacheOperation) 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)CMSD_setImageLoadOperation:(id)operation forKey:(NSString *)key { 27 | [self CMSD_cancelImageLoadOperationWithKey:key]; 28 | NSMutableDictionary *operationDictionary = [self operationDictionary]; 29 | [operationDictionary setObject:operation forKey:key]; 30 | } 31 | 32 | - (void)CMSD_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(CMSDWebImageOperation)]){ 44 | [(id) operations cancel]; 45 | } 46 | [operationDictionary removeObjectForKey:key]; 47 | } 48 | } 49 | 50 | - (void)CMSD_removeImageLoadOperationWithKey:(NSString *)key { 51 | NSMutableDictionary *operationDictionary = [self operationDictionary]; 52 | [operationDictionary removeObjectForKey:key]; 53 | } 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /MXScrollView/MXEnumHeader.h: -------------------------------------------------------------------------------- 1 | // 2 | // MXScrollHeader.h 3 | // MXScrollViewDemo 4 | // 5 | // Created by apple on 16/3/23. 6 | // Copyright © 2016年 PRO. All rights reserved. 7 | // 8 | 9 | #ifndef MXEnumHeader_h 10 | #define MXEnumHeader_h 11 | 12 | #import 13 | 14 | typedef NS_ENUM(NSInteger, kMXScrollViewDirection) { 15 | /** 16 | * 水平滚动 17 | */ 18 | kMXScrollViewDirectionHorizontal, 19 | /** 20 | * 竖直滚动 21 | */ 22 | kMXScrollViewDirectionVertical 23 | }; 24 | 25 | //竖直滚动方向 26 | typedef NS_ENUM(NSInteger, kMXVerticalDirection) { 27 | /** 28 | * 从上到下 29 | */ 30 | kMXVerticalDirectionFromTop, 31 | /** 32 | * 从下到上 33 | */ 34 | kMXVerticalDirectionFromBottom 35 | }; 36 | 37 | //特效类型 38 | typedef NS_ENUM(NSInteger, kMXTransitionType) { 39 | /** 40 | * 交叉淡化过渡 41 | */ 42 | kMXTransitionFade, 43 | /** 44 | * 新视图移到旧视图上面 45 | */ 46 | kMXTransitionMoveIn, 47 | /** 48 | * 新视图把旧视图推出去 49 | */ 50 | kMXTransitionPush, 51 | /** 52 | * 将旧视图移开,显示下面的新视图 53 | */ 54 | kMXTransitionReveal, 55 | /** 56 | * 向上翻一页(私有API,可能影响审核) 57 | */ 58 | kMXTransitionPageCurl, 59 | /** 60 | * 向下翻一页(私有API,可能影响审核) 61 | */ 62 | kMXTransitionPageUnCurl, 63 | /** 64 | * 滴水效果(私有API,可能影响审核) 65 | */ 66 | kMXTransitionRippleEffect, 67 | /** 68 | * 收缩效果,如同mac的神奇效果(私有API,可能影响审核) 69 | */ 70 | kMXTransitionSuckEffect, 71 | /** 72 | * 立方体效果(私有API,可能影响审核) 73 | */ 74 | kMXTransitionCube, 75 | /** 76 | * 上下翻转效果(私有API,可能影响审核) 77 | */ 78 | kMXTransitionOglFlip, 79 | /** 80 | * 随机效果(私有API,可能影响审核) 81 | */ 82 | kMXTransitionRandom 83 | }; 84 | 85 | //特效方向 86 | typedef NS_ENUM(NSInteger, kMXTransitionDirection) { 87 | /** 88 | * 从右到左 89 | */ 90 | kMXTransitionDirectionFromRight, 91 | /** 92 | * 从左到右 93 | */ 94 | kMXTransitionDirectionFromLeft, 95 | /** 96 | * 从下到上 97 | */ 98 | kMXTransitionDirectionFromBottom, 99 | /** 100 | * 从上到下 101 | */ 102 | kMXTransitionDirectionFromTop, 103 | /** 104 | * 随机 105 | */ 106 | kMXTransitionDirectionRandom 107 | }; 108 | 109 | //pageControl位置 110 | typedef NS_ENUM(NSInteger, kMXPageControlPosition) { 111 | /** 112 | * 上面 113 | */ 114 | kMXPageControlPositionTop, 115 | /** 116 | * 下面 117 | */ 118 | kMXPageControlPositionBottom, 119 | /** 120 | * 左边 121 | */ 122 | kMXPageControlPositionLeft, 123 | /** 124 | * 右边 125 | */ 126 | kMXPageControlPositionRight, 127 | }; 128 | 129 | #endif /* MXScrollHeader_h */ 130 | -------------------------------------------------------------------------------- /MXScrollView/MXImageScrollView.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import "MXEnumHeader.h" 3 | #import "MXPageControl.h" 4 | @class MXImageScrollView; 5 | 6 | @protocol MXScrollViewDelegate 7 | 8 | @optional 9 | /**添加图片左视图 图片下标index*/ 10 | - (UIView *)MXScrollView:(MXImageScrollView* )mxScrollView viewForLeftAccessoryViewAtIndex:(NSInteger)index; 11 | 12 | /**左视图跟随拉伸的效果 图片下标index*/ 13 | - (UIViewAutoresizing)MXScrollView:(MXImageScrollView *)mxScrollView leftAccessoryViewAutoresizingMaskAtIndex:(NSInteger)index ; 14 | 15 | /**添加图片右视图 图片下标index*/ 16 | - (UIView *)MXScrollView:(MXImageScrollView *)mxScrollView viewForRightAccessoryViewAtIndex:(NSInteger)index; 17 | 18 | /**右视图跟随拉伸的效果 图片下标index*/ 19 | - (UIViewAutoresizing)MXScrollView:(MXImageScrollView *)mxScrollView rightAccessoryViewAutoresizingMaskAtIndex:(NSInteger)index ; 20 | 21 | @end 22 | 23 | @interface MXImageScrollView : UIView 24 | 25 | /**传入的图片数组(支持传入图片或图片地址)*/ 26 | @property (nonatomic, strong) NSArray *images; 27 | 28 | /**点击事件*/ 29 | @property (nonatomic, copy) void (^tapImageHandle)(NSInteger index); 30 | 31 | /**滑动到某一页回调*/ 32 | @property (nonatomic, copy) void (^didScrollImageViewAtIndexHandle)(NSInteger index); 33 | 34 | /**滚动方向(默认横向) 竖直滚动时注意系统对滚动视图的自动布局*/ 35 | @property (nonatomic, assign) kMXScrollViewDirection scrollDirection; 36 | 37 | /**竖直滚动时滚动方向(默认从上到下)*/ 38 | @property (nonatomic, assign) kMXVerticalDirection verticalDirection; 39 | 40 | /**是否有导航栏 默认为yes 拉伸模式下顶部无导航栏须设置为NO*/ 41 | @property (nonatomic, assign) BOOL hasNavigationBar; 42 | 43 | /**是否循环滚动 default is yes*/ 44 | @property (nonatomic, assign) BOOL loopScroll; 45 | 46 | /**自动换页 default is yes*/ 47 | @property (nonatomic, assign) BOOL autoScroll; 48 | 49 | /**是否显示切换动画 default is no*/ 50 | @property (nonatomic, assign) BOOL showAnimotion; 51 | 52 | /**是否显示pageControl 默认为yes*/ 53 | @property (nonatomic, assign) BOOL showPageIndicator; 54 | 55 | /**滑动间隔 default is 3s*/ 56 | @property (nonatomic, assign) float scrollIntervalTime; 57 | 58 | /**一次动画所需时间 default is 0.5s*/ 59 | @property (nonatomic, assign) float animotionDuringTime; 60 | 61 | 62 | /**内部滚动视图*/ 63 | @property (nonatomic, readonly, strong) UIScrollView *rootScrollView; 64 | 65 | /**内部表视图*/ 66 | @property (nonatomic, readonly, strong) UITableView *rootTableView; 67 | 68 | /**pageControll分页视图*/ 69 | @property (nonatomic, readonly, strong) MXPageControl *pageControl; 70 | 71 | /**预加载视图,须写在设置图片数组之前*/ 72 | @property (nonatomic, strong) UIImage *placeholderImage; 73 | 74 | /**pageControl位置,上,下,左,又,四个位置*/ 75 | @property (nonatomic, assign) kMXPageControlPosition pageControlPosition; 76 | 77 | /**animotion*/ 78 | @property (nonatomic, strong) CATransition *animation; 79 | 80 | /**动画类型*/ 81 | @property (nonatomic, assign) kMXTransitionType animotionType; 82 | 83 | /**动画方向*/ 84 | @property (nonatomic, assign) kMXTransitionDirection animotionDirection; 85 | 86 | @property (nonatomic, assign) id delegate; 87 | 88 | #pragma mark - 方法 89 | 90 | /** 91 | * 普通模式创建一个MXScrollView 92 | * 93 | * @param frame 位置 94 | * 95 | * @return 实例化对象 96 | */ 97 | - (instancetype)initWithFrame:(CGRect)frame; 98 | 99 | 100 | /** 101 | * TableView模式(无导航栏需设置hasNavigationBar为NO) 102 | * 103 | * @param frame 位置 104 | * @param rootTableView 根TableView 105 | * 106 | * @return 实例化对象 107 | */ 108 | - (instancetype)initWithFrame:(CGRect)frame 109 | rootTableView:(UITableView *)rootTableView; 110 | 111 | /** 112 | * 拉伸图片 加载在tableView上面时,须在scrollViewDidScroll代理中实现本方法方可拉伸图片 113 | */ 114 | - (void)stretchingSubviews; 115 | 116 | /** 117 | * 释放定时器,可以写在viewWillDisappear里 118 | */ 119 | - (void)invalidateTimer; 120 | 121 | @end 122 | -------------------------------------------------------------------------------- /MXScrollView/MXImageView.h: -------------------------------------------------------------------------------- 1 | // 2 | // MXImageView.h 3 | // MXScrollViewDemo 4 | // 5 | // Created by apple on 16/3/24. 6 | // Copyright © 2016年 PRO. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MXEnumHeader.h" 11 | 12 | @interface MXImageView : UIImageView 13 | 14 | @property (nonatomic, copy) void (^didTapImageViewHandle)(); 15 | 16 | - (instancetype)initWithFrame:(CGRect)frame 17 | hasTable:(BOOL)hasTable; 18 | 19 | - (void)setImageWithSource:(id)imageSource 20 | placeholderImage:(UIImage *)placeholderImage; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /MXScrollView/MXImageView.m: -------------------------------------------------------------------------------- 1 | // 2 | // MXImageView.m 3 | // MXScrollViewDemo 4 | // 5 | // Created by apple on 16/3/24. 6 | // Copyright © 2016年 PRO. All rights reserved. 7 | // 8 | 9 | #import "MXImageView.h" 10 | #import "UIImageView+CMWebCache.h" 11 | 12 | @implementation MXImageView 13 | 14 | - (instancetype)initWithFrame:(CGRect)frame 15 | hasTable:(BOOL)hasTable { 16 | self = [super initWithFrame:frame]; 17 | if (self) { 18 | self.autoresizesSubviews = YES; 19 | self.userInteractionEnabled = YES; 20 | self.backgroundColor = [UIColor clearColor]; 21 | self.contentMode = hasTable ? UIViewContentModeScaleAspectFill : UIViewContentModeScaleToFill; 22 | 23 | UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] 24 | initWithTarget:self 25 | action:@selector(tapImageView:)]; 26 | [self addGestureRecognizer:tap]; 27 | } 28 | return self; 29 | } 30 | 31 | - (void)setImageWithSource:(id)imageSource 32 | placeholderImage:(UIImage *)placeholderImage { 33 | if ([imageSource isKindOfClass:[UIImage class]]) { 34 | self.image = (UIImage *)imageSource; 35 | } else if ([imageSource isKindOfClass:[NSString class]]) { 36 | [self CMSD_setImageWithURL:[NSURL URLWithString:(NSString *)imageSource] 37 | placeholderImage:placeholderImage]; 38 | } 39 | 40 | } 41 | 42 | - (void)tapImageView:(UITapGestureRecognizer *)tap { 43 | if (self.didTapImageViewHandle) { 44 | self.didTapImageViewHandle(); 45 | } 46 | } 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /MXScrollView/MXPageControl.h: -------------------------------------------------------------------------------- 1 | // 2 | // MXPageControl.h 3 | // MXScrollViewDemo 4 | // 5 | // Created by apple on 16/3/24. 6 | // Copyright © 2016年 PRO. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MXEnumHeader.h" 11 | 12 | @interface MXPageControl : UIPageControl 13 | 14 | - (instancetype)initWithFrame:(CGRect)frame 15 | superViewHeight:(CGFloat)superViewHeight 16 | pages:(NSInteger)pages; 17 | 18 | - (void)setPosition:(kMXPageControlPosition)pisition; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /MXScrollView/MXPageControl.m: -------------------------------------------------------------------------------- 1 | // 2 | // MXPageControl.m 3 | // MXScrollViewDemo 4 | // 5 | // Created by apple on 16/3/24. 6 | // Copyright © 2016年 PRO. All rights reserved. 7 | // 8 | 9 | #import "MXPageControl.h" 10 | #import "MXScrollConst.h" 11 | 12 | @interface MXPageControl () 13 | 14 | @property (nonatomic, assign) CGFloat scrollViewWidth; 15 | @property (nonatomic, assign) CGFloat scrollViewHeight; 16 | 17 | @end 18 | 19 | @implementation MXPageControl 20 | 21 | - (instancetype)initWithFrame:(CGRect)frame 22 | superViewHeight:(CGFloat)superViewHeight 23 | pages:(NSInteger)pages { 24 | self = [super initWithFrame:frame]; 25 | if (self) { 26 | self.numberOfPages = pages; 27 | self.userInteractionEnabled = NO; 28 | self.backgroundColor = [UIColor clearColor]; 29 | self.currentPageIndicatorTintColor = KDEFAULT_PAGECONTROL_COLOR; 30 | self.autoresizingMask = UIViewAutoresizingFlexibleTopMargin; 31 | _scrollViewWidth = CGRectGetWidth(frame); 32 | _scrollViewHeight = superViewHeight; 33 | } 34 | return self; 35 | } 36 | 37 | - (void)setPosition:(kMXPageControlPosition)pisition { 38 | switch (pisition) { 39 | case kMXPageControlPositionBottom: { 40 | self.frame = CGRectMake(0, 41 | _scrollViewHeight - kMXPageControlHeight, 42 | _scrollViewWidth, 43 | kMXPageControlHeight); 44 | } 45 | break; 46 | case kMXPageControlPositionTop: { 47 | self.frame = CGRectMake(0, 0, _scrollViewWidth, kMXPageControlHeight); 48 | } 49 | break; 50 | case kMXPageControlPositionLeft: { 51 | self.frame = CGRectMake(- _scrollViewHeight / 2 + kMXPageControlHeight / 2, 52 | (_scrollViewHeight - kMXPageControlHeight) / 2, 53 | _scrollViewHeight, 54 | kMXPageControlHeight); 55 | self.transform = CGAffineTransformMakeRotation(M_PI_2); 56 | } 57 | break; 58 | case kMXPageControlPositionRight: { 59 | self.frame = CGRectMake(_scrollViewWidth - _scrollViewHeight / 2 - kMXPageControlHeight / 2, 60 | (_scrollViewHeight - kMXPageControlHeight) / 2, 61 | _scrollViewHeight, 62 | kMXPageControlHeight); 63 | self.transform = CGAffineTransformMakeRotation(M_PI_2); 64 | } 65 | break; 66 | default: 67 | break; 68 | } 69 | } 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /MXScrollView/MXScrollConst.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __MXScrollConst__H__ 3 | #define __MXScrollConst__H__ 4 | 5 | #import 6 | 7 | #define KDEFAULT_PAGECONTROL_COLOR [UIColor whiteColor] //默认pageControl当前页数颜色 8 | #define KDEFAULT_PLACEHOLDER_IMAGE [UIImage imageNamed:@"MXScrollView.bundle/placeholderPicture"] //默认等待视图 9 | 10 | extern CGFloat const kMXScrollViewHeight; //默认滚动视图高度 11 | extern CGFloat const kMXPageControlHeight; //pageControl高度 12 | extern CGFloat const kMXNavigationBarHeight;//导航栏高度 13 | 14 | extern float const kMXScrollDuringTime; //默认滚动时间 15 | extern float const kMXAnimotionDuringTime; //默认动画时间 16 | 17 | extern int const kAnimotionTypeCounts;//动画类型数量 18 | extern int const kAnimotionDirectionCounts;//动画方向数量 19 | 20 | #endif -------------------------------------------------------------------------------- /MXScrollView/MXScrollConst.m: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __MXScrollConst__M__ 3 | #define __MXScrollConst__M__ 4 | 5 | #import 6 | #import 7 | 8 | CGFloat const kMXScrollViewHeight = 200; //默认滚动视图高度 9 | CGFloat const kMXPageControlHeight = 20; //pageControl高度 10 | CGFloat const kMXNavigationBarHeight = 64;//导航栏高度 11 | 12 | float const kMXScrollDuringTime = 3.0f; //默认滚动时间 13 | float const kMXAnimotionDuringTime = .5f; //默认动画时间 14 | 15 | int const kAnimotionTypeCounts = 10;//动画类型数量 16 | int const kAnimotionDirectionCounts = 4;//动画方向数量 17 | 18 | #endif -------------------------------------------------------------------------------- /MXScrollView/MXScrollView.bundle/placeholderPicture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cwxatlm/MXScrollView/2d8ceb9b358998cad4d02f28968d0806c1645882/MXScrollView/MXScrollView.bundle/placeholderPicture.png -------------------------------------------------------------------------------- /MXScrollView/MXScrollView.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef MXScrollView_h 3 | #define MXScrollView_h 4 | 5 | #import "MXEnumHeader.h" 6 | #import "MXImageScrollView.h" 7 | #import "MXImageView.h" 8 | #import "MXPageControl.h" 9 | 10 | #endif -------------------------------------------------------------------------------- /MXScrollView/MXTransaction.h: -------------------------------------------------------------------------------- 1 | // 2 | // MXTransaction.h 3 | // MXScrollViewDemo 4 | // 5 | // Created by apple on 16/4/5. 6 | // Copyright © 2016年 PRO. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MXEnumHeader.h" 11 | 12 | @interface MXTransaction : CATransaction 13 | 14 | /***Create default transition*/ 15 | + (CATransition *)defaultTransition; 16 | 17 | /***Get system animotion type from kCMTransitionType*/ 18 | + (NSString *)getAnimotionType:(kMXTransitionType)CMType; 19 | 20 | /***Get system AnimotionDirection kCMTransitionType*/ 21 | + (NSString *)getAnimotionDirection:(kMXTransitionDirection)CMDirection; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /MXScrollView/MXTransaction.m: -------------------------------------------------------------------------------- 1 | // 2 | // MXTransaction.m 3 | // MXScrollViewDemo 4 | // 5 | // Created by apple on 16/4/5. 6 | // Copyright © 2016年 PRO. All rights reserved. 7 | // 8 | 9 | #import "MXTransaction.h" 10 | #import "MXScrollConst.h" 11 | 12 | @implementation MXTransaction 13 | 14 | + (CATransition *)defaultTransition { 15 | CATransition *animation = [CATransition animation]; 16 | animation.duration = kMXAnimotionDuringTime; 17 | animation.type = [self getAnimotionType:kMXTransitionMoveIn]; 18 | animation.subtype = [self getAnimotionDirection:kMXTransitionDirectionFromRight]; 19 | return animation; 20 | } 21 | 22 | + (NSString *)getAnimotionType:(kMXTransitionType)MXType { 23 | switch (MXType) { 24 | case kMXTransitionMoveIn: 25 | return kCATransitionMoveIn; 26 | case kMXTransitionFade: 27 | return kCATransitionFade; 28 | case kMXTransitionPush: 29 | return kCATransitionPush; 30 | case kMXTransitionReveal: 31 | return kCATransitionReveal; 32 | case kMXTransitionPageCurl: 33 | return @"pageCurl"; 34 | case kMXTransitionPageUnCurl: 35 | return @"pageUnCurl"; 36 | case kMXTransitionCube: 37 | return @"cube"; 38 | case kMXTransitionOglFlip: 39 | return @"oglFlip"; 40 | case kMXTransitionRippleEffect: 41 | return @"rippleEffect"; 42 | case kMXTransitionSuckEffect: 43 | return @"suckEffect"; 44 | case kMXTransitionRandom: 45 | return [self getAnimotionType:arc4random_uniform(kAnimotionTypeCounts)]; 46 | default: 47 | break; 48 | } 49 | } 50 | 51 | + (NSString *)getAnimotionDirection:(kMXTransitionDirection)MXDirection { 52 | switch (MXDirection) { 53 | case kMXTransitionDirectionFromBottom: 54 | return kCATransitionFromBottom; 55 | case kMXTransitionDirectionFromLeft: 56 | return kCATransitionFromLeft; 57 | case kMXTransitionDirectionFromRight: 58 | return kCATransitionFromRight; 59 | case kMXTransitionDirectionFromTop: 60 | return kCATransitionFromTop; 61 | case kMXTransitionDirectionRandom: 62 | return [self getAnimotionDirection:arc4random_uniform(kAnimotionDirectionCounts)]; 63 | default: 64 | break; 65 | } 66 | } 67 | 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /MXScrollViewDemo.xcodeproj/xcshareddata/xcschemes/MXScrollFramework.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /MXScrollViewDemo/AnimationViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // AnimationViewController.h 3 | // MXScrollViewDemo 4 | // 5 | // Created by apple on 16/4/7. 6 | // Copyright © 2016年 PRO. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AnimationViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /MXScrollViewDemo/AnimationViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // AnimationViewController.m 3 | // MXScrollViewDemo 4 | // 5 | // Created by apple on 16/4/7. 6 | // Copyright © 2016年 PRO. All rights reserved. 7 | // 8 | 9 | #import "AnimationViewController.h" 10 | #import "MXScrollView.h" 11 | 12 | #define Screen_Rect [UIScreen mainScreen].bounds 13 | 14 | @interface AnimationViewController () 15 | 16 | @property (nonatomic, strong) NSMutableArray *scrollViews; 17 | 18 | @end 19 | 20 | @implementation AnimationViewController 21 | 22 | - (void)viewWillDisappear:(BOOL)animated { 23 | [super viewWillDisappear:animated]; 24 | [_scrollViews enumerateObjectsUsingBlock:^(MXImageScrollView *scroll, 25 | NSUInteger idx, 26 | BOOL * _Nonnull stop) { 27 | [scroll invalidateTimer]; 28 | }]; 29 | } 30 | 31 | - (void)viewDidLoad { 32 | [super viewDidLoad]; 33 | // Do any additional setup after loading the view. 34 | 35 | self.view.backgroundColor = [UIColor whiteColor]; 36 | _scrollViews = [NSMutableArray array]; 37 | 38 | CGFloat scrollViewWidth = 150; 39 | CGFloat scrollViewHeight = 120; 40 | 41 | CGFloat x_gap = (CGRectGetWidth(Screen_Rect) - scrollViewWidth * 2) / 3; 42 | CGFloat y_gap = x_gap; 43 | for (int i=0; i<4; i++) { 44 | CGFloat scrollViewX = (scrollViewWidth + x_gap) * (i % 2) + x_gap; 45 | CGFloat scrollViewY = (scrollViewHeight + y_gap) * (i / 2) + y_gap + 64; 46 | MXImageScrollView *scroll = [[MXImageScrollView alloc] initWithFrame:CGRectMake(scrollViewX, 47 | scrollViewY, 48 | scrollViewWidth, 49 | scrollViewHeight)]; 50 | scroll.showAnimotion = YES; 51 | scroll.animotionType = kMXTransitionRandom; 52 | scroll.animotionDirection = kMXTransitionDirectionRandom; 53 | scroll.images = @[[UIImage imageNamed:@"picture_1"], 54 | [UIImage imageNamed:@"picture_2"], 55 | [UIImage imageNamed:@"picture_3"]]; 56 | [self.view addSubview:scroll]; 57 | [_scrollViews addObject:scroll]; 58 | } 59 | } 60 | 61 | - (void)didReceiveMemoryWarning { 62 | [super didReceiveMemoryWarning]; 63 | // Dispose of any resources that can be recreated. 64 | } 65 | 66 | /* 67 | #pragma mark - Navigation 68 | 69 | // In a storyboard-based application, you will often want to do a little preparation before navigation 70 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 71 | // Get the new view controller using [segue destinationViewController]. 72 | // Pass the selected object to the new view controller. 73 | } 74 | */ 75 | 76 | @end 77 | -------------------------------------------------------------------------------- /MXScrollViewDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | 2 | #import 3 | 4 | @interface AppDelegate : UIResponder 5 | 6 | @property (strong, nonatomic) UIWindow *window; 7 | 8 | 9 | @end 10 | 11 | -------------------------------------------------------------------------------- /MXScrollViewDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // MXScrollViewDemo 4 | // 5 | // Created by PRO on 16/2/23. 6 | // Copyright © 2016年 PRO. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "ViewController.h" 11 | 12 | @interface AppDelegate () 13 | 14 | @end 15 | 16 | @implementation AppDelegate 17 | 18 | 19 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 20 | // Override point for customization after application launch. 21 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 22 | self.window.backgroundColor = [UIColor whiteColor]; 23 | self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]]; 24 | [self.window makeKeyAndVisible]; 25 | return YES; 26 | } 27 | 28 | - (void)applicationWillResignActive:(UIApplication *)application { 29 | // 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. 30 | // 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. 31 | } 32 | 33 | - (void)applicationDidEnterBackground:(UIApplication *)application { 34 | // 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. 35 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 36 | } 37 | 38 | - (void)applicationWillEnterForeground:(UIApplication *)application { 39 | // 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. 40 | } 41 | 42 | - (void)applicationDidBecomeActive:(UIApplication *)application { 43 | // 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. 44 | } 45 | 46 | - (void)applicationWillTerminate:(UIApplication *)application { 47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 48 | } 49 | 50 | @end 51 | -------------------------------------------------------------------------------- /MXScrollViewDemo/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 | } -------------------------------------------------------------------------------- /MXScrollViewDemo/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /MXScrollViewDemo/Assets.xcassets/house.imageset/Alarm_213px_1194720_easyicon.net.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cwxatlm/MXScrollView/2d8ceb9b358998cad4d02f28968d0806c1645882/MXScrollViewDemo/Assets.xcassets/house.imageset/Alarm_213px_1194720_easyicon.net.png -------------------------------------------------------------------------------- /MXScrollViewDemo/Assets.xcassets/house.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "Alarm_213px_1194720_easyicon.net.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /MXScrollViewDemo/Assets.xcassets/island.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "Sun_128px_1194839_easyicon.net.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /MXScrollViewDemo/Assets.xcassets/island.imageset/Sun_128px_1194839_easyicon.net.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cwxatlm/MXScrollView/2d8ceb9b358998cad4d02f28968d0806c1645882/MXScrollViewDemo/Assets.xcassets/island.imageset/Sun_128px_1194839_easyicon.net.png -------------------------------------------------------------------------------- /MXScrollViewDemo/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 | -------------------------------------------------------------------------------- /MXScrollViewDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /MXScrollViewDemo/EasyUseViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // EasyUseViewController.h 3 | // MXScrollViewDemo 4 | // 5 | // Created by apple on 16/4/5. 6 | // Copyright © 2016年 PRO. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface EasyUseViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /MXScrollViewDemo/EasyUseViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // EasyUseViewController.m 3 | // MXScrollViewDemo 4 | // 5 | // Created by apple on 16/4/5. 6 | // Copyright © 2016年 PRO. All rights reserved. 7 | // 8 | 9 | #import "EasyUseViewController.h" 10 | #import "MXScrollView.h" 11 | 12 | #define Screen_Width [UIScreen mainScreen].bounds 13 | static CGFloat const scrollViewWidth = 300; 14 | static CGFloat const scrollViewHeight = 200; 15 | 16 | @interface EasyUseViewController () 17 | { 18 | MXImageScrollView *scroll; 19 | } 20 | @end 21 | 22 | @implementation EasyUseViewController 23 | 24 | - (void)viewWillDisappear:(BOOL)animated { 25 | [super viewWillDisappear:animated]; 26 | [scroll invalidateTimer]; 27 | } 28 | 29 | - (void)viewDidLoad { 30 | [super viewDidLoad]; 31 | // Do any additional setup after loading the view. 32 | self.view.backgroundColor = [UIColor whiteColor]; 33 | 34 | scroll = [[MXImageScrollView alloc] initWithFrame:CGRectMake((CGRectGetWidth(Screen_Width) - scrollViewWidth) / 2, 35 | scrollViewHeight, 36 | scrollViewWidth, 37 | scrollViewHeight)]; 38 | scroll.images = @[[UIImage imageNamed:@"picture_1"], 39 | [UIImage imageNamed:@"picture_2"], 40 | [UIImage imageNamed:@"picture_3"]]; 41 | [scroll setTapImageHandle:^(NSInteger index) { 42 | UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" 43 | message:[NSString 44 | stringWithFormat:@"你点击了%ld张图片", index] 45 | delegate:nil 46 | cancelButtonTitle:nil 47 | otherButtonTitles:@"Ok", nil]; 48 | [alertView show]; 49 | }]; 50 | 51 | [scroll setDidScrollImageViewAtIndexHandle:^(NSInteger index) { 52 | NSLog(@"滑动到了第%ld页", index); 53 | }]; 54 | 55 | [self.view addSubview:scroll]; 56 | } 57 | 58 | 59 | 60 | - (void)didReceiveMemoryWarning { 61 | [super didReceiveMemoryWarning]; 62 | // Dispose of any resources that can be recreated. 63 | } 64 | 65 | /* 66 | #pragma mark - Navigation 67 | 68 | // In a storyboard-based application, you will often want to do a little preparation before navigation 69 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 70 | // Get the new view controller using [segue destinationViewController]. 71 | // Pass the selected object to the new view controller. 72 | } 73 | */ 74 | 75 | @end 76 | -------------------------------------------------------------------------------- /MXScrollViewDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | NSAppTransportSecurity 40 | 41 | NSAllowsArbitraryLoads 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /MXScrollViewDemo/TableUseViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // TbaleUseViewController.h 3 | // MXScrollViewDemo 4 | // 5 | // Created by apple on 16/4/5. 6 | // Copyright © 2016年 PRO. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface TableUseViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /MXScrollViewDemo/TableUseViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // TbaleUseViewController.m 3 | // MXScrollViewDemo 4 | // 5 | // Created by apple on 16/4/5. 6 | // Copyright © 2016年 PRO. All rights reserved. 7 | // 8 | 9 | #import "TableUseViewController.h" 10 | #import "MXScrollView.h" 11 | 12 | #define Screen_Width [UIScreen mainScreen].bounds.size.width 13 | static CGFloat const scrollViewHeight = 220; 14 | 15 | static NSString *const tableViewCellIdentifer = @"tableViewCellIdentifer"; 16 | 17 | @interface TableUseViewController () 18 | { 19 | MXImageScrollView *scroll; 20 | } 21 | @end 22 | 23 | @implementation TableUseViewController 24 | 25 | - (void)viewWillDisappear:(BOOL)animated { 26 | [super viewWillDisappear:animated]; 27 | [scroll invalidateTimer]; 28 | } 29 | 30 | - (void)viewDidLoad { 31 | [super viewDidLoad]; 32 | // Do any additional setup after loading the view. 33 | self.view.backgroundColor = [UIColor whiteColor]; 34 | 35 | UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds 36 | style:UITableViewStylePlain]; 37 | [tableView registerClass:[UITableViewCell class] 38 | forCellReuseIdentifier:tableViewCellIdentifer]; 39 | tableView.delegate = self; 40 | tableView.dataSource = self; 41 | tableView.showsVerticalScrollIndicator = NO; 42 | [self.view addSubview:tableView]; 43 | 44 | scroll = [[MXImageScrollView alloc] initWithFrame:CGRectMake(0, 45 | 0, 46 | Screen_Width, 47 | scrollViewHeight) 48 | rootTableView:tableView]; 49 | scroll.delegate = self; 50 | scroll.images = @[[UIImage imageNamed:@"picture_1"], 51 | [UIImage imageNamed:@"picture_2"], 52 | [UIImage imageNamed:@"picture_3"]]; 53 | 54 | } 55 | 56 | #pragma mark - scrollView delegate 57 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView { 58 | #warning 想拉伸必须实现此方法 59 | [scroll stretchingSubviews]; 60 | } 61 | 62 | #pragma mark - MXScrollView delegate 63 | - (UIView *)MXScrollView:(MXImageScrollView *)mxScrollView viewForLeftAccessoryViewAtIndex:(NSInteger)index { 64 | UIImageView *leftImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 65 | scrollViewHeight - 40, 66 | 30, 67 | 30)]; 68 | leftImageView.image = [UIImage imageNamed:@"house"]; 69 | return leftImageView; 70 | } 71 | 72 | - (UIView *)MXScrollView:(MXImageScrollView *)mxScrollView viewForRightAccessoryViewAtIndex:(NSInteger)index { 73 | UIImageView *rightImageView = [[UIImageView alloc] initWithFrame:CGRectMake(Screen_Width - 40, 74 | scrollViewHeight - 40, 75 | 30, 76 | 30)]; 77 | rightImageView.image = [UIImage imageNamed:@"island"]; 78 | return rightImageView; 79 | } 80 | 81 | - (UIViewAutoresizing)MXScrollView:(MXImageScrollView *)mxScrollView leftAccessoryViewAutoresizingMaskAtIndex:(NSInteger)index { 82 | return UIViewAutoresizingFlexibleTopMargin; 83 | } 84 | 85 | - (UIViewAutoresizing)MXScrollView:(MXImageScrollView *)mxScrollView rightAccessoryViewAutoresizingMaskAtIndex:(NSInteger)index { 86 | return UIViewAutoresizingFlexibleTopMargin; 87 | } 88 | 89 | #pragma mark - tableVeiw delegate 90 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 91 | return 20; 92 | } 93 | 94 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 95 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableViewCellIdentifer 96 | forIndexPath:indexPath]; 97 | cell.textLabel.text = [NSString stringWithFormat:@"%ld", indexPath.row]; 98 | return cell; 99 | } 100 | 101 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 102 | [tableView deselectRowAtIndexPath:indexPath animated:YES]; 103 | } 104 | 105 | - (void)didReceiveMemoryWarning { 106 | [super didReceiveMemoryWarning]; 107 | // Dispose of any resources that can be recreated. 108 | } 109 | 110 | /* 111 | #pragma mark - Navigation 112 | 113 | // In a storyboard-based application, you will often want to do a little preparation before navigation 114 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 115 | // Get the new view controller using [segue destinationViewController]. 116 | // Pass the selected object to the new view controller. 117 | } 118 | */ 119 | 120 | @end 121 | -------------------------------------------------------------------------------- /MXScrollViewDemo/VerticalUseViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // VerticalUseViewController.h 3 | // MXScrollViewDemo 4 | // 5 | // Created by apple on 16/4/7. 6 | // Copyright © 2016年 PRO. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface VerticalUseViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /MXScrollViewDemo/VerticalUseViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // VerticalUseViewController.m 3 | // MXScrollViewDemo 4 | // 5 | // Created by apple on 16/4/7. 6 | // Copyright © 2016年 PRO. All rights reserved. 7 | // 8 | 9 | #import "VerticalUseViewController.h" 10 | #import "MXScrollView.h" 11 | 12 | #define Screen_Rect [UIScreen mainScreen].bounds 13 | 14 | @interface VerticalUseViewController () 15 | { 16 | MXImageScrollView *scroll1; 17 | MXImageScrollView *scroll2; 18 | } 19 | @end 20 | 21 | @implementation VerticalUseViewController 22 | 23 | - (void)viewWillDisappear:(BOOL)animated { 24 | [super viewWillDisappear:animated]; 25 | [scroll1 invalidateTimer]; 26 | [scroll2 invalidateTimer]; 27 | } 28 | 29 | - (void)viewDidLoad { 30 | [super viewDidLoad]; 31 | // Do any additional setup after loading the view. 32 | self.view.backgroundColor = [UIColor whiteColor]; 33 | 34 | self.automaticallyAdjustsScrollViewInsets = NO; 35 | 36 | CGFloat scrollViewHeight = (CGRectGetHeight(Screen_Rect) - 64 - 150) / 2; 37 | CGFloat scrollViewWidth = CGRectGetWidth(Screen_Rect) - 60; 38 | 39 | scroll1 = [[MXImageScrollView alloc] initWithFrame:CGRectMake(30, 40 | 50 + 64, 41 | scrollViewWidth, 42 | scrollViewHeight)]; 43 | scroll1.scrollDirection = kMXScrollViewDirectionVertical; 44 | scroll1.pageControlPosition = kMXPageControlPositionLeft; 45 | scroll1.images = @[[UIImage imageNamed:@"picture_1"], 46 | [UIImage imageNamed:@"picture_2"], 47 | [UIImage imageNamed:@"picture_3"]]; 48 | [self.view addSubview:scroll1]; 49 | 50 | 51 | scroll2 = [[MXImageScrollView alloc] initWithFrame:CGRectMake(30, 52 | CGRectGetMaxY(scroll1.frame) + 50, 53 | scrollViewWidth, 54 | scrollViewHeight)]; 55 | scroll2.scrollDirection = kMXScrollViewDirectionVertical; 56 | scroll2.verticalDirection = kMXVerticalDirectionFromBottom; 57 | scroll2.images = @[[UIImage imageNamed:@"picture_1"], 58 | [UIImage imageNamed:@"picture_2"], 59 | [UIImage imageNamed:@"picture_3"]]; 60 | 61 | [self.view addSubview:scroll2]; 62 | } 63 | 64 | - (void)didReceiveMemoryWarning { 65 | [super didReceiveMemoryWarning]; 66 | // Dispose of any resources that can be recreated. 67 | } 68 | 69 | /* 70 | #pragma mark - Navigation 71 | 72 | // In a storyboard-based application, you will often want to do a little preparation before navigation 73 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 74 | // Get the new view controller using [segue destinationViewController]. 75 | // Pass the selected object to the new view controller. 76 | } 77 | */ 78 | 79 | @end 80 | -------------------------------------------------------------------------------- /MXScrollViewDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // MXScrollViewDemo 4 | // 5 | // Created by PRO on 16/2/23. 6 | // Copyright © 2016年 PRO. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /MXScrollViewDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // CMCyclicScrollDemo 4 | // 5 | // Created by apple on 16/2/19. 6 | // Copyright © 2016年 desn. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "EasyUseViewController.h" 11 | #import "TableUseViewController.h" 12 | #import "VerticalUseViewController.h" 13 | #import "AnimationViewController.h" 14 | 15 | static NSString *const tableIdentifier = @"TableViewCell"; 16 | 17 | @interface ViewController () 18 | 19 | @property (nonatomic, strong) UITableView *tableView; 20 | 21 | @end 22 | 23 | @implementation ViewController 24 | 25 | - (void)viewDidLoad { 26 | [super viewDidLoad]; 27 | // Do any additional setup after loading the view, typically from a nib. 28 | [self initBaseData]; 29 | } 30 | 31 | - (void)initBaseData { 32 | self.title = @"MXScrollView"; 33 | [self.navigationController.navigationBar setTitleTextAttributes:@{ 34 | NSForegroundColorAttributeName:[UIColor lightGrayColor]}]; 35 | self.navigationController.navigationBar.tintColor = [UIColor lightGrayColor]; 36 | 37 | _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped]; 38 | [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:tableIdentifier]; 39 | _tableView.delegate = self; 40 | _tableView.dataSource = self; 41 | [self.view addSubview:_tableView]; 42 | 43 | } 44 | 45 | #pragma mark - tabelView delegate 46 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 47 | return 4; 48 | } 49 | 50 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 51 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableIdentifier forIndexPath:indexPath]; 52 | switch (indexPath.row) { 53 | case 0: { 54 | cell.textLabel.text = @"EasyUseViewController"; 55 | } 56 | break; 57 | case 1: { 58 | cell.textLabel.text = @"TableUseViewController"; 59 | } 60 | break; 61 | case 2: { 62 | cell.textLabel.text = @"VerticalUseViewController"; 63 | } 64 | break; 65 | case 3: { 66 | cell.textLabel.text = @"AnimationViewController"; 67 | } 68 | break; 69 | default: 70 | break; 71 | } 72 | return cell; 73 | } 74 | 75 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 76 | [tableView deselectRowAtIndexPath:indexPath animated:YES]; 77 | switch (indexPath.row) { 78 | case 0: { 79 | [self.navigationController pushViewController:[[EasyUseViewController alloc] init] animated:YES]; 80 | } 81 | break; 82 | case 1: { 83 | [self.navigationController pushViewController:[[TableUseViewController alloc] init] animated:YES]; 84 | } 85 | break; 86 | case 2: { 87 | [self.navigationController pushViewController:[[VerticalUseViewController alloc] init] animated:YES]; 88 | } 89 | break; 90 | case 3: { 91 | [self.navigationController pushViewController:[[AnimationViewController alloc] init] animated:YES]; 92 | } 93 | break; 94 | default: 95 | break; 96 | } 97 | } 98 | 99 | - (void)didReceiveMemoryWarning { 100 | [super didReceiveMemoryWarning]; 101 | // Dispose of any resources that can be recreated. 102 | } 103 | 104 | @end 105 | -------------------------------------------------------------------------------- /MXScrollViewDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // MXScrollViewDemo 4 | // 5 | // Created by PRO on 16/2/23. 6 | // Copyright © 2016年 PRO. 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 | -------------------------------------------------------------------------------- /Pictures/gif_one.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cwxatlm/MXScrollView/2d8ceb9b358998cad4d02f28968d0806c1645882/Pictures/gif_one.gif -------------------------------------------------------------------------------- /Pictures/gif_two.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cwxatlm/MXScrollView/2d8ceb9b358998cad4d02f28968d0806c1645882/Pictures/gif_two.gif -------------------------------------------------------------------------------- /Pictures/picture_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cwxatlm/MXScrollView/2d8ceb9b358998cad4d02f28968d0806c1645882/Pictures/picture_1.png -------------------------------------------------------------------------------- /Pictures/picture_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cwxatlm/MXScrollView/2d8ceb9b358998cad4d02f28968d0806c1645882/Pictures/picture_2.png -------------------------------------------------------------------------------- /Pictures/picture_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cwxatlm/MXScrollView/2d8ceb9b358998cad4d02f28968d0806c1645882/Pictures/picture_3.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MXScrollView 2 | 3 | The use of a simple with the effects of the rolling cycle view 4 | ----- 5 | 一款易用的可拉伸的自动循环滚动视图 集成简单易懂 自定义性强 6 | ----- 7 | 8 | 9 | ![demo](Pictures/gif_one.gif) 10 | ![demo](Pictures/gif_two.gif) 11 | 12 | 版本1.2.3 13 | ---- 14 | 1.2.3 增加支持竖直滚动 //support Vertical scroll 15 | 16 | 17 | 使用 How to Use it 18 | ===== 19 | 20 | ## Installation 21 | 22 | ### CocoaPods 23 | 24 | 你可以使用cocapods导入 you can use it in cocoapods 25 | ``` 26 | pod 'MXScrollView' 27 | ``` 28 | 29 | ### Carthage 30 | 31 | [Carthage](https://github.com/Carthage/Carthage) 也是一个很好的管理三方框架的工具 32 | 33 | * You can install Carthage with [Homebrew](http://brew.sh/) using the following command: 34 | * 你可以使用[Homebrew](http://brew.sh/)来安装Carthage 35 | * 安装完homebrew后执行下面命令 36 | 37 | ```bash 38 | $ brew update 39 | $ brew install carthage 40 | ``` 41 | 42 | 在你的工程里创建一个`Cartfile`文件 ,并在里面写上下面这句话 43 | 44 | ```ogdl 45 | github "cwxatlm/MXScrollView" 46 | ``` 47 | 48 | 在终端里执行`carthage update` 49 | * 安装好后只需要在对应 Target 中的 Build Setting 中的 Framework Search Path 项加入以下路径 50 | * `$(SRCROOT)/Carthage/Build/iOS` 51 | 52 | 导入头文件 53 | `#import ` 54 | 55 | 想对Carthage了解更多也可以看这里[让自己的项目支持Carthage](http://www.jianshu.com/p/bf263c596538) 56 | 57 | ### Manually 手动导入 58 | * Drag the `MXScrollView` folder into your project. 把`MXScrollView`文件夹拖入工程 59 | * `Targets->Build Phases->Copy Bundle Resources`. 60 | * `#imprort "MXScrollView.h"` 61 | 62 | 有两种使用方式 you can use it in two ways 63 | ### 1.像普通控件一样使用它 use it looks like normal View 64 | 65 | 66 | ####Objective-C 67 | ```objective-c 68 | MXImageScrollView *scroll = [[MXIMageScrollView alloc] initWithFrame:CGRectMake(x, y, scrollWidth, scrollHeight)]; 69 | //数组支持传入image或imageUrl support image or imageUrl 70 | scroll.images = @[ 71 | [UIImage imageNamed:@"picture_one"], 72 | [UIImage imageNamed:@"picture_two"], 73 | [UIImage imageNamed:@"picture_three"], 74 | @"http://pic31.nipic.com/20130624/8821914_104949466000_2.jpg" 75 | ]; 76 | scroll.animotionType = kMXTransitionRandom; //支持多特效 support serveral type 77 | scroll.animotionDirection = kMXTransitionDirectionRandom; //支持多方向 support serveral direction 78 | [self.view addSubview:scroll]; 79 | 80 | [scroll setTapImageHandle:^(NSInteger index) { 81 | //支持点击事件 support tap 82 | }]; 83 | 84 | //在你不需要的时候释放他 例如 release the timer 85 | - (void)viewWillDisappear:(BOOL)animated { 86 | [scroll invalidateTimer]; 87 | } 88 | ``` 89 | 90 | ### 2.加载在tableView上 load it in tableView 91 | 92 | 此时必须写为全局变量 93 | 94 | ####Objective-C 95 | ```objective-c 96 | _scroll = [[MXImageScrollView alloc] initWithFrame:CGRectMake(0, 97 | 0, 98 | CGRectGetWidth(self.view.bounds), 99 | MXScrollViewHeight) 100 | rootTableView:_tableView]; 101 | _scroll.animotionDirection = kMXTransitionDirectionRandom; 102 | _scroll.animotionType = kMXTransitionRandom; 103 | _scroll.pageControlPosition = kMXPageControlPositionCenter; //更改pageControl显示的位置 104 | _scroll.images = @[ 105 | [UIImage imageNamed:@"picture_one"], 106 | [UIImage imageNamed:@"picture_two"], 107 | [UIImage imageNamed:@"picture_three"], 108 | @"http://pic31.nipic.com/20130624/8821914_104949466000_2.jpg" 109 | ]; 110 | 111 | [_scroll setTapImageHandle:^(NSInteger index) { 112 | //tap 113 | }]; 114 | 115 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView { 116 | #warning 重要,想拉伸必须实现此方法 must implement this method 117 | [_scroll stretchingImage]; 118 | } 119 | 120 | //在你不需要的时候释放他 例如 release the timer 121 | - (void)viewWillDisappear:(BOOL)animated { 122 | [_scroll invalidateTimer]; 123 | } 124 | ``` 125 | 126 | ### delegate 127 | 128 | ``` 129 | 130 | _scroll.delegate = self; 131 | 132 | //delegate method 给图片增加副视图 133 | - (UIView *)MXScrollView:(MXScrollView *)mxScrollView viewForImageLeftAccessoryViewAtIndex:(NSInteger)index { 134 | UILabel *leftLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 150, 50, 20)]; 135 | leftLabel.backgroundColor = [UIColor clearColor]; 136 | leftLabel.textColor = [UIColor whiteColor]; 137 | leftLabel.text = [NSString stringWithFormat:@"第%ld页", index]; 138 | return leftLabel; 139 | } 140 | 141 | //视图拉伸效果 142 | - (UIViewAutoresizing)MXScrollView:(MXScrollView *)mxScrollView leftAccessoryViewAutoresizingMaskAtIndex:(NSInteger)index { 143 | switch (index) { 144 | case 0: 145 | return UIViewAutoresizingFlexibleBottomMargin; 146 | break; 147 | default: 148 | return UIViewAutoresizingFlexibleTopMargin; 149 | break; 150 | } 151 | } 152 | 153 | 154 | ``` 155 | 156 | ### 更多用法请参考Demo more example read in Demo 157 | --------------------------------------------------------------------------------