├── CycleView_OC_Demo
├── CycleView_OC_Demo
│ ├── Images.xcassets
│ │ ├── 01.imageset
│ │ │ ├── 01.png
│ │ │ └── Contents.json
│ │ ├── 02.imageset
│ │ │ ├── 02.png
│ │ │ └── Contents.json
│ │ ├── 03.imageset
│ │ │ ├── 03.png
│ │ │ └── Contents.json
│ │ ├── 04.imageset
│ │ │ ├── 04.png
│ │ │ └── Contents.json
│ │ ├── 05.imageset
│ │ │ ├── 05.png
│ │ │ └── Contents.json
│ │ ├── 06.imageset
│ │ │ ├── 06.png
│ │ │ └── Contents.json
│ │ ├── 07.imageset
│ │ │ ├── 07.png
│ │ │ └── Contents.json
│ │ ├── 08.imageset
│ │ │ ├── 08.png
│ │ │ └── Contents.json
│ │ ├── 09.imageset
│ │ │ ├── 09.png
│ │ │ └── Contents.json
│ │ ├── 10.imageset
│ │ │ ├── 10.png
│ │ │ └── Contents.json
│ │ ├── 11.imageset
│ │ │ ├── 11.png
│ │ │ └── Contents.json
│ │ ├── 12.imageset
│ │ │ ├── 12.png
│ │ │ └── Contents.json
│ │ ├── 13.imageset
│ │ │ ├── 13.png
│ │ │ └── Contents.json
│ │ ├── 14.imageset
│ │ │ ├── 14.png
│ │ │ └── Contents.json
│ │ ├── 15.imageset
│ │ │ ├── 15.png
│ │ │ └── Contents.json
│ │ ├── 16.imageset
│ │ │ ├── 16.png
│ │ │ └── Contents.json
│ │ └── AppIcon.appiconset
│ │ │ └── Contents.json
│ ├── ViewController.h
│ ├── CycleViewController.h
│ ├── AppDelegate.h
│ ├── CycleViewCommenController.h
│ ├── main.m
│ ├── CycleViewCommenController.m
│ ├── Info.plist
│ ├── CycleViewController.m
│ ├── ViewController.m
│ ├── AppDelegate.m
│ └── Base.lproj
│ │ ├── LaunchScreen.xib
│ │ └── Main.storyboard
├── CycleView_OC_Demo.xcodeproj
│ └── project.xcworkspace
│ │ └── contents.xcworkspacedata
└── CycleView_OC_DemoTests
│ ├── Info.plist
│ └── CycleView_OC_DemoTests.m
├── Classes
├── UIImage+color.h
├── NSTimer+SRTimer.h
├── PictureCycleViewController.h
├── PictureCycleCell.h
├── UIImage+color.m
├── NSTimer+SRTimer.m
├── PictureCycleCell.m
├── CycleAnimatorViewController.h
├── CycleAnimatorViewController.m
└── PictureCycleViewController.m
├── CycleView_OC.xcworkspace
└── contents.xcworkspacedata
├── SDWebImage
├── UIImage+MultiFormat.h
├── SDWebImageOperation.h
├── UIImage+GIF.h
├── SDWebImageDecoder.h
├── NSData+ImageContentType.h
├── UIView+WebCacheOperation.h
├── NSData+ImageContentType.m
├── SDWebImageCompat.m
├── SDWebImageCompat.h
├── UIView+WebCacheOperation.m
├── SDWebImageDecoder.m
├── SDWebImageDownloaderOperation.h
├── UIImage+MultiFormat.m
├── SDWebImagePrefetcher.h
├── UIImageView+HighlightedWebCache.m
├── UIImageView+HighlightedWebCache.h
├── UIImage+GIF.m
├── SDWebImagePrefetcher.m
├── SDWebImageDownloader.h
├── SDImageCache.h
├── UIImageView+WebCache.m
├── UIImageView+WebCache.h
├── SDWebImageDownloader.m
├── SDWebImageManager.h
├── UIButton+WebCache.m
└── UIButton+WebCache.h
├── .gitignore
├── CycleView_OC
├── CycleView_OC
│ ├── CycleView_OC.h
│ └── Info.plist
└── CycleView_OCTests
│ ├── Info.plist
│ └── CycleView_OCTests.m
├── LICENSE
├── README.md
└── CycleView_OC.podspec
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/01.imageset/01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SarielTang/CycleView_OC/HEAD/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/01.imageset/01.png
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/02.imageset/02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SarielTang/CycleView_OC/HEAD/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/02.imageset/02.png
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/03.imageset/03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SarielTang/CycleView_OC/HEAD/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/03.imageset/03.png
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/04.imageset/04.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SarielTang/CycleView_OC/HEAD/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/04.imageset/04.png
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/05.imageset/05.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SarielTang/CycleView_OC/HEAD/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/05.imageset/05.png
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/06.imageset/06.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SarielTang/CycleView_OC/HEAD/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/06.imageset/06.png
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/07.imageset/07.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SarielTang/CycleView_OC/HEAD/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/07.imageset/07.png
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/08.imageset/08.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SarielTang/CycleView_OC/HEAD/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/08.imageset/08.png
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/09.imageset/09.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SarielTang/CycleView_OC/HEAD/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/09.imageset/09.png
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/10.imageset/10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SarielTang/CycleView_OC/HEAD/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/10.imageset/10.png
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/11.imageset/11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SarielTang/CycleView_OC/HEAD/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/11.imageset/11.png
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/12.imageset/12.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SarielTang/CycleView_OC/HEAD/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/12.imageset/12.png
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/13.imageset/13.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SarielTang/CycleView_OC/HEAD/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/13.imageset/13.png
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/14.imageset/14.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SarielTang/CycleView_OC/HEAD/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/14.imageset/14.png
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/15.imageset/15.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SarielTang/CycleView_OC/HEAD/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/15.imageset/15.png
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/16.imageset/16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SarielTang/CycleView_OC/HEAD/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/16.imageset/16.png
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/ViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.h
3 | // CycleView_OC_Demo
4 | //
5 | // Created by SarielTang on 15/7/10.
6 | // Copyright (c) 2015年 SarielTang. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface ViewController : UITableViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/Classes/UIImage+color.h:
--------------------------------------------------------------------------------
1 | //
2 | // UIImage+color.h
3 | // WeZebra
4 | //
5 | // Created by SarielTang on 15/9/25.
6 | // Copyright © 2015年 wezebra.com. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface UIImage (color)
12 |
13 | // 颜色转换为背景图片
14 | + (UIImage *)imageWithColor:(UIColor *)color;
15 |
16 | @end
17 |
--------------------------------------------------------------------------------
/CycleView_OC.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/SDWebImage/UIImage+MultiFormat.h:
--------------------------------------------------------------------------------
1 | //
2 | // UIImage+MultiFormat.h
3 | // SDWebImage
4 | //
5 | // Created by Olivier Poitrey on 07/06/13.
6 | // Copyright (c) 2013 Dailymotion. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface UIImage (MultiFormat)
12 |
13 | + (UIImage *)sd_imageWithData:(NSData *)data;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/CycleViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // CycleViewController.h
3 | // CycleView_OC_Demo
4 | //
5 | // Created by SarielTang on 15/7/10.
6 | // Copyright (c) 2015年 SarielTang. All rights reserved.
7 | //
8 | #import
9 | //#import "CycleView_OC.h"
10 |
11 | @interface CycleViewController : CycleAnimatorViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // CycleView_OC_Demo
4 | //
5 | // Created by SarielTang on 15/7/10.
6 | // Copyright (c) 2015年 SarielTang. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface AppDelegate : UIResponder
12 |
13 | @property (strong, nonatomic) UIWindow *window;
14 |
15 |
16 | @end
17 |
18 |
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/CycleViewCommenController.h:
--------------------------------------------------------------------------------
1 | //
2 | // CycleViewCommenController.h
3 | // CycleView_OC_Demo
4 | //
5 | // Created by SarielTang on 15/12/7.
6 | // Copyright © 2015年 SarielTang. All rights reserved.
7 | //
8 |
9 | #import
10 | //#import "CycleView_OC.h"
11 |
12 | @interface CycleViewCommenController : PictureCycleViewController
13 |
14 | @end
15 |
--------------------------------------------------------------------------------
/SDWebImage/SDWebImageOperation.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import
10 |
11 | @protocol SDWebImageOperation
12 |
13 | - (void)cancel;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/Classes/NSTimer+SRTimer.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSTimer+SRTimer.h
3 | // CycleView_OC
4 | //
5 | // Created by SarielTang on 15/10/17.
6 | // Copyright © 2015年 SarielTang. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface NSTimer (SRTimer)
12 |
13 | - (void)startTimer;
14 | - (void)pauseTimer;
15 | - (void)resumeTimer;
16 | - (void)resumeTimerAfterTimeInterval:(NSTimeInterval)interval;
17 |
18 | @end
19 |
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // CycleView_OC_Demo
4 | //
5 | // Created by SarielTang on 15/7/10.
6 | // Copyright (c) 2015年 SarielTang. 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 |
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/01.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x",
6 | "filename" : "01.png"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/02.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x",
6 | "filename" : "02.png"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/03.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x",
6 | "filename" : "03.png"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/04.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x",
6 | "filename" : "04.png"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/05.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x",
6 | "filename" : "05.png"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/06.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x",
6 | "filename" : "06.png"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/07.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x",
6 | "filename" : "07.png"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/08.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x",
6 | "filename" : "08.png"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/09.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x",
6 | "filename" : "09.png"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/10.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x",
6 | "filename" : "10.png"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/11.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x",
6 | "filename" : "11.png"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/12.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x",
6 | "filename" : "12.png"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/13.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x",
6 | "filename" : "13.png"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/14.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x",
6 | "filename" : "14.png"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/15.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x",
6 | "filename" : "15.png"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.xcassets/16.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "scale" : "1x",
6 | "filename" : "16.png"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "scale" : "2x"
11 | },
12 | {
13 | "idiom" : "universal",
14 | "scale" : "3x"
15 | }
16 | ],
17 | "info" : {
18 | "version" : 1,
19 | "author" : "xcode"
20 | }
21 | }
--------------------------------------------------------------------------------
/SDWebImage/UIImage+GIF.h:
--------------------------------------------------------------------------------
1 | //
2 | // UIImage+GIF.h
3 | // LBGIFImage
4 | //
5 | // Created by Laurin Brandner on 06.01.12.
6 | // Copyright (c) 2012 __MyCompanyName__. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface UIImage (GIF)
12 |
13 | + (UIImage *)sd_animatedGIFNamed:(NSString *)name;
14 |
15 | + (UIImage *)sd_animatedGIFWithData:(NSData *)data;
16 |
17 | - (UIImage *)sd_animatedImageByScalingAndCroppingToSize:(CGSize)size;
18 |
19 | @end
20 |
--------------------------------------------------------------------------------
/SDWebImage/SDWebImageDecoder.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * Created by james on 9/28/11.
6 | *
7 | * For the full copyright and license information, please view the LICENSE
8 | * file that was distributed with this source code.
9 | */
10 |
11 | #import
12 | #import "SDWebImageCompat.h"
13 |
14 | @interface UIImage (ForceDecode)
15 |
16 | + (UIImage *)decodedImageWithImage:(UIImage *)image;
17 |
18 | @end
19 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Xcode
2 | #
3 | build/
4 | *.pbxuser
5 | !default.pbxuser
6 | *.mode1v3
7 | !default.mode1v3
8 | *.mode2v3
9 | !default.mode2v3
10 | *.perspectivev3
11 | !default.perspectivev3
12 | xcuserdata
13 | *.xccheckout
14 | *.moved-aside
15 | DerivedData
16 | *.hmap
17 | *.ipa
18 | *.xcuserstate
19 |
20 | # CocoaPods
21 | #
22 | # We recommend against adding the Pods directory to your .gitignore. However
23 | # you should judge for yourself, the pros and cons are mentioned at:
24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
25 | #
26 | #Pods/
27 |
--------------------------------------------------------------------------------
/SDWebImage/NSData+ImageContentType.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Fabrice Aneche on 06/01/14.
3 | // Copyright (c) 2014 Dailymotion. All rights reserved.
4 | //
5 |
6 | #import
7 |
8 | @interface NSData (ImageContentType)
9 |
10 | /**
11 | * Compute the content type for an image data
12 | *
13 | * @param data the input data
14 | *
15 | * @return the content type as string (i.e. image/jpeg, image/gif)
16 | */
17 | + (NSString *)sd_contentTypeForImageData:(NSData *)data;
18 |
19 | @end
20 |
21 |
22 | @interface NSData (ImageContentTypeDeprecated)
23 |
24 | + (NSString *)contentTypeForImageData:(NSData *)data __deprecated_msg("Use `sd_contentTypeForImageData:`");
25 |
26 | @end
27 |
--------------------------------------------------------------------------------
/Classes/PictureCycleViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // PictureCycleViewController.h
3 | // S01-图片轮播()
4 | //
5 | // Created by Jerry on 15/7/3.
6 | // Copyright (c) 2015年 Jerry. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface PictureCycleViewController : UICollectionViewController
12 |
13 | @property (nonatomic,assign,getter=isNetImage)BOOL netImage;
14 |
15 | /// 图片数组
16 | @property (nonatomic, strong) NSArray *cycleImageList;
17 |
18 | // 图片url数组
19 | @property (nonatomic,strong) NSArray *cycleImageUrls;
20 |
21 | /// 轮播时间间隔,默认2秒
22 | @property (nonatomic, assign) NSUInteger cycleTimeInterval;
23 |
24 | // 占位图片
25 | @property (nonatomic,strong) UIImage *placeholderImage;
26 |
27 | @end
28 |
--------------------------------------------------------------------------------
/CycleView_OC/CycleView_OC/CycleView_OC.h:
--------------------------------------------------------------------------------
1 | //
2 | // CycleView_OC.h
3 | // CycleView_OC
4 | //
5 | // Created by SarielTang on 15/7/10.
6 | // Copyright (c) 2015年 SarielTang. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | //! Project version number for CycleView_OC.
12 | FOUNDATION_EXPORT double CycleView_OCVersionNumber;
13 |
14 | //! Project version string for CycleView_OC.
15 | FOUNDATION_EXPORT const unsigned char CycleView_OCVersionString[];
16 |
17 | // In this header, you should import all the public headers of your framework using statements like #import
18 |
19 | #import "PictureCycleViewController.h"
20 | #import "PictureCycleCell.h"
21 | #import "CycleAnimatorViewController.h"
22 |
--------------------------------------------------------------------------------
/Classes/PictureCycleCell.h:
--------------------------------------------------------------------------------
1 | //
2 | // PictureCycleCell.h
3 | // S01-图片轮播()
4 | //
5 | // Created by Jerry on 15/7/3.
6 | // Copyright (c) 2015年 Jerry. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @protocol PictureCycleCellDelegate
12 |
13 | /// cell 被点击
14 | - (void)pictureCycleCellDidSelected:(NSInteger)itemTag;
15 |
16 | @end
17 |
18 |
19 | @interface PictureCycleCell : UICollectionViewCell
20 |
21 | /// 图片
22 | @property (nonatomic, strong) UIImageView *imageView;
23 |
24 | /// image
25 | @property (nonatomic, strong) UIImage *image;
26 |
27 | /// tag
28 | @property (nonatomic, assign) NSInteger itemTag;
29 |
30 | /// delegate
31 | @property (nonatomic, assign) id delegate;
32 |
33 | @end
34 |
--------------------------------------------------------------------------------
/Classes/UIImage+color.m:
--------------------------------------------------------------------------------
1 | //
2 | // UIImage+color.m
3 | // WeZebra
4 | //
5 | // Created by SarielTang on 15/9/25.
6 | // Copyright © 2015年 wezebra.com. All rights reserved.
7 | //
8 |
9 | #import "UIImage+color.h"
10 |
11 | @implementation UIImage (color)
12 |
13 | // 颜色转换为背景图片
14 | + (UIImage *)imageWithColor:(UIColor *)color {
15 | CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
16 | UIGraphicsBeginImageContext(rect.size);
17 | CGContextRef context = UIGraphicsGetCurrentContext();
18 |
19 | CGContextSetFillColorWithColor(context, [color CGColor]);
20 | CGContextFillRect(context, rect);
21 |
22 | UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
23 | UIGraphicsEndImageContext();
24 |
25 | return image;
26 | }
27 |
28 | @end
29 |
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Images.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 | }
--------------------------------------------------------------------------------
/CycleView_OC/CycleView_OCTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | club.Sariel.$(PRODUCT_NAME:rfc1034identifier)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_DemoTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | club.Sariel.$(PRODUCT_NAME:rfc1034identifier)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/CycleView_OC/CycleView_OC/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 |
--------------------------------------------------------------------------------
/Classes/NSTimer+SRTimer.m:
--------------------------------------------------------------------------------
1 | //
2 | // NSTimer+SRTimer.m
3 | // CycleView_OC
4 | //
5 | // Created by SarielTang on 15/10/17.
6 | // Copyright © 2015年 SarielTang. All rights reserved.
7 | //
8 |
9 | #import "NSTimer+SRTimer.h"
10 |
11 | @implementation NSTimer (SRTimer)
12 |
13 | - (void)startTimer {
14 | if ([self isValid]) {
15 | return;
16 | }
17 |
18 | // [self setFireDate:[NSDate distantPast]];//开启
19 | [self fire];
20 | }
21 |
22 | - (void)pauseTimer{
23 | if (![self isValid]) {
24 | return ;
25 | }
26 |
27 | [self setFireDate:[NSDate distantFuture]]; //如果给我一个期限,我希望是4001-01-01 00:00:00 +0000
28 | }
29 |
30 |
31 | - (void)resumeTimer{
32 | if (![self isValid]) {
33 | return ;
34 | }
35 |
36 | [self setFireDate:[NSDate date]];
37 | }
38 |
39 | - (void)resumeTimerAfterTimeInterval:(NSTimeInterval)interval
40 | {
41 | if (![self isValid]) {
42 | return ;
43 | }
44 | [self setFireDate:[NSDate dateWithTimeIntervalSinceNow:interval]];
45 | }
46 |
47 | @end
48 |
--------------------------------------------------------------------------------
/CycleView_OC/CycleView_OCTests/CycleView_OCTests.m:
--------------------------------------------------------------------------------
1 | //
2 | // CycleView_OCTests.m
3 | // CycleView_OCTests
4 | //
5 | // Created by SarielTang on 15/7/10.
6 | // Copyright (c) 2015年 SarielTang. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | @interface CycleView_OCTests : XCTestCase
13 |
14 | @end
15 |
16 | @implementation CycleView_OCTests
17 |
18 | - (void)setUp {
19 | [super setUp];
20 | // Put setup code here. This method is called before the invocation of each test method in the class.
21 | }
22 |
23 | - (void)tearDown {
24 | // Put teardown code here. This method is called after the invocation of each test method in the class.
25 | [super tearDown];
26 | }
27 |
28 | - (void)testExample {
29 | // This is an example of a functional test case.
30 | XCTAssert(YES, @"Pass");
31 | }
32 |
33 | - (void)testPerformanceExample {
34 | // This is an example of a performance test case.
35 | [self measureBlock:^{
36 | // Put the code you want to measure the time of here.
37 | }];
38 | }
39 |
40 | @end
41 |
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_DemoTests/CycleView_OC_DemoTests.m:
--------------------------------------------------------------------------------
1 | //
2 | // CycleView_OC_DemoTests.m
3 | // CycleView_OC_DemoTests
4 | //
5 | // Created by SarielTang on 15/7/10.
6 | // Copyright (c) 2015年 SarielTang. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | @interface CycleView_OC_DemoTests : XCTestCase
13 |
14 | @end
15 |
16 | @implementation CycleView_OC_DemoTests
17 |
18 | - (void)setUp {
19 | [super setUp];
20 | // Put setup code here. This method is called before the invocation of each test method in the class.
21 | }
22 |
23 | - (void)tearDown {
24 | // Put teardown code here. This method is called after the invocation of each test method in the class.
25 | [super tearDown];
26 | }
27 |
28 | - (void)testExample {
29 | // This is an example of a functional test case.
30 | XCTAssert(YES, @"Pass");
31 | }
32 |
33 | - (void)testPerformanceExample {
34 | // This is an example of a performance test case.
35 | [self measureBlock:^{
36 | // Put the code you want to measure the time of here.
37 | }];
38 | }
39 |
40 | @end
41 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 汤晔
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/SDWebImage/UIView+WebCacheOperation.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import
10 | #import "SDWebImageManager.h"
11 |
12 | @interface UIView (WebCacheOperation)
13 |
14 | /**
15 | * Set the image load operation (storage in a UIView based dictionary)
16 | *
17 | * @param operation the operation
18 | * @param key key for storing the operation
19 | */
20 | - (void)sd_setImageLoadOperation:(id)operation forKey:(NSString *)key;
21 |
22 | /**
23 | * Cancel all operations for the current UIView and key
24 | *
25 | * @param key key for identifying the operations
26 | */
27 | - (void)sd_cancelImageLoadOperationWithKey:(NSString *)key;
28 |
29 | /**
30 | * Just remove the operations corresponding to the current UIView and key without cancelling them
31 | *
32 | * @param key key for identifying the operations
33 | */
34 | - (void)sd_removeImageLoadOperationWithKey:(NSString *)key;
35 |
36 | @end
37 |
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/CycleViewCommenController.m:
--------------------------------------------------------------------------------
1 | //
2 | // CycleViewCommenController.m
3 | // CycleView_OC_Demo
4 | //
5 | // Created by SarielTang on 15/12/7.
6 | // Copyright © 2015年 SarielTang. All rights reserved.
7 | //
8 |
9 | #import "CycleViewCommenController.h"
10 |
11 | @interface CycleViewCommenController ()
12 |
13 | @end
14 |
15 | @implementation CycleViewCommenController
16 |
17 | - (void)viewDidLoad {
18 | [super viewDidLoad];
19 |
20 | // NSMutableArray *arrayM = [NSMutableArray array];
21 | //
22 | // for (int i = 0; i < 5; ++i) {
23 | //
24 | // NSString *imageName = [NSString stringWithFormat:@"%02d.jpg", i + 1];
25 | // [arrayM addObject:[UIImage imageNamed:imageName]];
26 | // }
27 |
28 | #pragma mark - required
29 | //You should set the size of the view
30 | //设置视图的大小
31 | [self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
32 |
33 | //You should set the image array
34 | //设置图片数组
35 | // self.cycleImageList = arrayM;
36 | //设置网络图片
37 | self.netImage = YES;
38 | }
39 |
40 | - (void)pictureCycleCellDidSelected:(NSInteger)itemTag {
41 | NSLog(@"点击了图片%ld",itemTag);
42 | }
43 |
44 | @end
45 |
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIMainStoryboardFile
28 | Main
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | UISupportedInterfaceOrientations
34 |
35 | UIInterfaceOrientationPortrait
36 | UIInterfaceOrientationLandscapeLeft
37 | UIInterfaceOrientationLandscapeRight
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/SDWebImage/NSData+ImageContentType.m:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Fabrice Aneche on 06/01/14.
3 | // Copyright (c) 2014 Dailymotion. All rights reserved.
4 | //
5 |
6 | #import "NSData+ImageContentType.h"
7 |
8 |
9 | @implementation NSData (ImageContentType)
10 |
11 | + (NSString *)sd_contentTypeForImageData:(NSData *)data {
12 | uint8_t c;
13 | [data getBytes:&c length:1];
14 | switch (c) {
15 | case 0xFF:
16 | return @"image/jpeg";
17 | case 0x89:
18 | return @"image/png";
19 | case 0x47:
20 | return @"image/gif";
21 | case 0x49:
22 | case 0x4D:
23 | return @"image/tiff";
24 | case 0x52:
25 | // R as RIFF for WEBP
26 | if ([data length] < 12) {
27 | return nil;
28 | }
29 |
30 | NSString *testString = [[NSString alloc] initWithData:[data subdataWithRange:NSMakeRange(0, 12)] encoding:NSASCIIStringEncoding];
31 | if ([testString hasPrefix:@"RIFF"] && [testString hasSuffix:@"WEBP"]) {
32 | return @"image/webp";
33 | }
34 |
35 | return nil;
36 | }
37 | return nil;
38 | }
39 |
40 | @end
41 |
42 |
43 | @implementation NSData (ImageContentTypeDeprecated)
44 |
45 | + (NSString *)contentTypeForImageData:(NSData *)data {
46 | return [self sd_contentTypeForImageData:data];
47 | }
48 |
49 | @end
50 |
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/CycleViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // CycleViewController.m
3 | // CycleView_OC_Demo
4 | //
5 | // Created by SarielTang on 15/7/10.
6 | // Copyright (c) 2015年 SarielTang. All rights reserved.
7 | //
8 |
9 | #import "CycleViewController.h"
10 |
11 | @interface CycleViewController ()
12 |
13 | @end
14 |
15 | @implementation CycleViewController
16 |
17 | - (void)viewDidLoad {
18 | [super viewDidLoad];
19 |
20 | NSMutableArray *arrayM = [NSMutableArray array];
21 |
22 | for (int i = 0; i < 5; ++i) {
23 |
24 | NSString *imageName = [NSString stringWithFormat:@"%02d.jpg", i + 1];
25 | [arrayM addObject:[UIImage imageNamed:imageName]];
26 | }
27 |
28 | #pragma mark - required
29 | //You should set the size of the view
30 | //设置视图的大小
31 | [self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
32 |
33 | //You should set the image array
34 | //设置图片数组
35 | self.animatorImageList = arrayM;
36 |
37 | #pragma mark - optional
38 | //you can modify the animation effect by enumeration type
39 | //可以通过枚举类型,修改动画效果
40 | self.animationType = SRTransitionAnimateTypeRippleEffect;
41 |
42 | //You can set the picture carousel time interval
43 | //可以设置图片轮播的时间间隔
44 | self.cycleTimeInterval = 4;
45 |
46 | //You can set whether to limit the page switching in the animation implementation process
47 | //可以设置是否限制在动画执行过程中进行页面切换
48 | self.isLimitGestureWhenAnimating = NO;
49 |
50 | //you can change image's contentMode
51 | //可以设置图片填充模式
52 | self.animatorImageView.contentMode = UIViewContentModeScaleToFill;
53 | }
54 |
55 | @end
56 |
--------------------------------------------------------------------------------
/SDWebImage/SDWebImageCompat.m:
--------------------------------------------------------------------------------
1 | //
2 | // SDWebImageCompat.m
3 | // SDWebImage
4 | //
5 | // Created by Olivier Poitrey on 11/12/12.
6 | // Copyright (c) 2012 Dailymotion. All rights reserved.
7 | //
8 |
9 | #import "SDWebImageCompat.h"
10 |
11 | #if !__has_feature(objc_arc)
12 | #error SDWebImage is ARC only. Either turn on ARC for the project or use -fobjc-arc flag
13 | #endif
14 |
15 | inline UIImage *SDScaledImageForKey(NSString *key, UIImage *image) {
16 | if (!image) {
17 | return nil;
18 | }
19 |
20 | if ([image.images count] > 0) {
21 | NSMutableArray *scaledImages = [NSMutableArray array];
22 |
23 | for (UIImage *tempImage in image.images) {
24 | [scaledImages addObject:SDScaledImageForKey(key, tempImage)];
25 | }
26 |
27 | return [UIImage animatedImageWithImages:scaledImages duration:image.duration];
28 | }
29 | else {
30 | if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
31 | CGFloat scale = 1.0;
32 | if (key.length >= 8) {
33 | NSRange range = [key rangeOfString:@"@2x."];
34 | if (range.location != NSNotFound) {
35 | scale = 2.0;
36 | }
37 |
38 | range = [key rangeOfString:@"@3x."];
39 | if (range.location != NSNotFound) {
40 | scale = 3.0;
41 | }
42 | }
43 |
44 | UIImage *scaledImage = [[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:image.imageOrientation];
45 | image = scaledImage;
46 | }
47 | return image;
48 | }
49 | }
50 |
51 | NSString *const SDWebImageErrorDomain = @"SDWebImageErrorDomain";
52 |
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/ViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.m
3 | // CycleView_OC_Demo
4 | //
5 | // Created by SarielTang on 15/7/10.
6 | // Copyright (c) 2015年 SarielTang. All rights reserved.
7 | //
8 |
9 | #import "ViewController.h"
10 | #import "CycleViewController.h"
11 | #import "CycleViewCommenController.h"
12 |
13 | @interface ViewController ()
14 | //
15 |
16 | @end
17 |
18 | @implementation ViewController
19 |
20 | - (void)viewDidLoad {
21 | [super viewDidLoad];
22 | // CycleViewController *cycleView = [[CycleViewController alloc] init]; // 创建图片轮转
23 | CycleViewCommenController *cycleView = [[CycleViewCommenController alloc]init];
24 |
25 | [self addChildViewController:cycleView];// 添加控制
26 |
27 | //可以在任意位置加载这个url数组
28 | cycleView.cycleImageUrls = @[@"http://pic2.sc.chinaz.com/files/pic/pic9/201512/apic16892.jpg",@"http://pic14.nipic.com/20110522/7411759_164157418126_2.jpg",@"http://pic.nipic.com/2007-11-09/2007119122519868_2.jpg",@"http://pic24.nipic.com/20121022/9252150_193011306000_2.jpg"];
29 |
30 | self.tableView.tableHeaderView = cycleView.view;
31 | self.tableView.tableHeaderView.frame = CGRectMake(0, 0, self.view.frame.size.width, 200);
32 |
33 | // cycleView.delegate = self;
34 | }
35 |
36 | ///通过重写这个代理方法,即可进行点击图片后的交互处理.
37 | - (void)pictureCycleCellDidSelected:(NSInteger)itemTag{
38 | NSLog(@"被选中的item的tag值:%zd", itemTag);
39 | }
40 |
41 | - (void)didReceiveMemoryWarning {
42 | [super didReceiveMemoryWarning];
43 | // Dispose of any resources that can be recreated.
44 | }
45 |
46 | #pragma mark - Table view data source
47 |
48 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
49 | // Return the number of rows in the section.
50 | return 0;
51 | }
52 |
53 | @end
54 |
--------------------------------------------------------------------------------
/Classes/PictureCycleCell.m:
--------------------------------------------------------------------------------
1 | //
2 | // PictureCycleCell.m
3 | // S01-图片轮播()
4 | //
5 | // Created by Jerry on 15/7/3.
6 | // Copyright (c) 2015年 Jerry. All rights reserved.
7 | //
8 |
9 | #import "PictureCycleCell.h"
10 |
11 | @implementation PictureCycleCell
12 |
13 | //由于assign需要进行地址赋为空的操作,否则会出现野指针错误,所以需要进行释放.
14 | - (void)dealloc {
15 | _delegate = nil;
16 | }
17 |
18 | //自动布局
19 | - (instancetype)initWithFrame:(CGRect)frame {
20 |
21 | if (self = [super initWithFrame:frame]) {
22 | self.imageView.contentMode = UIViewContentModeScaleToFill;
23 | [self addSubview: self.imageView];
24 |
25 | // 设置 imageView 的约束 VFL
26 | [self.imageView setTranslatesAutoresizingMaskIntoConstraints:NO];
27 |
28 | NSArray *cons1 = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[imageView]-0-|" options:NSLayoutFormatAlignAllLeft metrics:nil views:@{@"imageView":self.imageView}];
29 |
30 | NSArray *cons2 = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[imageView]-0-|" options:NSLayoutFormatAlignAllLeft metrics:nil views:@{@"imageView" : self.imageView}];
31 |
32 | [self addConstraints:cons1];
33 | [self addConstraints:cons2];
34 | }
35 | return self;
36 | }
37 |
38 | // 当cell被点击的时候调用
39 | - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
40 | if (self.delegate) {
41 | if ([self.delegate respondsToSelector:@selector(pictureCycleCellDidSelected:)]) {
42 |
43 | [self.delegate pictureCycleCellDidSelected:self.itemTag];
44 | }
45 | }
46 | }
47 |
48 | #pragma mark - 属性 setter
49 | - (void)setImage:(UIImage *)image {
50 |
51 | if (image) {
52 |
53 | _image = image;
54 | self.imageView.image = image;
55 | }
56 | }
57 |
58 | #pragma mark - 懒加载
59 | - (UIImageView *)imageView {
60 |
61 | if (!_imageView) {
62 |
63 | _imageView = [[UIImageView alloc] init];
64 | }
65 | return _imageView;
66 | }
67 |
68 |
69 | @end
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/SDWebImage/SDWebImageCompat.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | * (c) Jamie Pinkham
5 | *
6 | * For the full copyright and license information, please view the LICENSE
7 | * file that was distributed with this source code.
8 | */
9 |
10 | #import
11 |
12 | #ifdef __OBJC_GC__
13 | #error SDWebImage does not support Objective-C Garbage Collection
14 | #endif
15 |
16 | #if __IPHONE_OS_VERSION_MIN_REQUIRED != 20000 && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_5_0
17 | #error SDWebImage doesn't support Deployement Target version < 5.0
18 | #endif
19 |
20 | #if !TARGET_OS_IPHONE
21 | #import
22 | #ifndef UIImage
23 | #define UIImage NSImage
24 | #endif
25 | #ifndef UIImageView
26 | #define UIImageView NSImageView
27 | #endif
28 | #else
29 |
30 | #import
31 |
32 | #endif
33 |
34 | #ifndef NS_ENUM
35 | #define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
36 | #endif
37 |
38 | #ifndef NS_OPTIONS
39 | #define NS_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type
40 | #endif
41 |
42 | #if OS_OBJECT_USE_OBJC
43 | #undef SDDispatchQueueRelease
44 | #undef SDDispatchQueueSetterSementics
45 | #define SDDispatchQueueRelease(q)
46 | #define SDDispatchQueueSetterSementics strong
47 | #else
48 | #undef SDDispatchQueueRelease
49 | #undef SDDispatchQueueSetterSementics
50 | #define SDDispatchQueueRelease(q) (dispatch_release(q))
51 | #define SDDispatchQueueSetterSementics assign
52 | #endif
53 |
54 | extern UIImage *SDScaledImageForKey(NSString *key, UIImage *image);
55 |
56 | typedef void(^SDWebImageNoParamsBlock)();
57 |
58 | extern NSString *const SDWebImageErrorDomain;
59 |
60 | #define dispatch_main_sync_safe(block)\
61 | if ([NSThread isMainThread]) {\
62 | block();\
63 | } else {\
64 | dispatch_sync(dispatch_get_main_queue(), block);\
65 | }
66 |
67 | #define dispatch_main_async_safe(block)\
68 | if ([NSThread isMainThread]) {\
69 | block();\
70 | } else {\
71 | dispatch_async(dispatch_get_main_queue(), block);\
72 | }
73 |
--------------------------------------------------------------------------------
/SDWebImage/UIView+WebCacheOperation.m:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import "UIView+WebCacheOperation.h"
10 | #import "objc/runtime.h"
11 |
12 | static char loadOperationKey;
13 |
14 | @implementation UIView (WebCacheOperation)
15 |
16 | - (NSMutableDictionary *)operationDictionary {
17 | NSMutableDictionary *operations = objc_getAssociatedObject(self, &loadOperationKey);
18 | if (operations) {
19 | return operations;
20 | }
21 | operations = [NSMutableDictionary dictionary];
22 | objc_setAssociatedObject(self, &loadOperationKey, operations, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
23 | return operations;
24 | }
25 |
26 | - (void)sd_setImageLoadOperation:(id)operation forKey:(NSString *)key {
27 | [self sd_cancelImageLoadOperationWithKey:key];
28 | NSMutableDictionary *operationDictionary = [self operationDictionary];
29 | [operationDictionary setObject:operation forKey:key];
30 | }
31 |
32 | - (void)sd_cancelImageLoadOperationWithKey:(NSString *)key {
33 | // Cancel in progress downloader from queue
34 | NSMutableDictionary *operationDictionary = [self operationDictionary];
35 | id operations = [operationDictionary objectForKey:key];
36 | if (operations) {
37 | if ([operations isKindOfClass:[NSArray class]]) {
38 | for (id operation in operations) {
39 | if (operation) {
40 | [operation cancel];
41 | }
42 | }
43 | } else if ([operations conformsToProtocol:@protocol(SDWebImageOperation)]){
44 | [(id) operations cancel];
45 | }
46 | [operationDictionary removeObjectForKey:key];
47 | }
48 | }
49 |
50 | - (void)sd_removeImageLoadOperationWithKey:(NSString *)key {
51 | NSMutableDictionary *operationDictionary = [self operationDictionary];
52 | [operationDictionary removeObjectForKey:key];
53 | }
54 |
55 | @end
56 |
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // CycleView_OC_Demo
4 | //
5 | // Created by SarielTang on 15/7/10.
6 | // Copyright (c) 2015年 SarielTang. All rights reserved.
7 | //
8 |
9 | #import "AppDelegate.h"
10 |
11 | @interface AppDelegate ()
12 |
13 | @end
14 |
15 | @implementation AppDelegate
16 |
17 |
18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
19 | // Override point for customization after application launch.
20 | return YES;
21 | }
22 |
23 | - (void)applicationWillResignActive:(UIApplication *)application {
24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
26 | }
27 |
28 | - (void)applicationDidEnterBackground:(UIApplication *)application {
29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
31 | }
32 |
33 | - (void)applicationWillEnterForeground:(UIApplication *)application {
34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
35 | }
36 |
37 | - (void)applicationDidBecomeActive:(UIApplication *)application {
38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
39 | }
40 |
41 | - (void)applicationWillTerminate:(UIApplication *)application {
42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
43 | }
44 |
45 | @end
46 |
--------------------------------------------------------------------------------
/Classes/CycleAnimatorViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // CycleAnimatorViewController.h
3 | // CycleView_OC
4 | //
5 | // Created by SarielTang on 15/10/17.
6 | // Copyright © 2015年 SarielTang. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | /*
12 | 动画类型 说明 对应常量 是否支持方向设置
13 | 公开API
14 | fade 淡出效果 kCATransitionFade 是
15 | movein 新视图移动到旧视图上 kCATransitionMoveIn 是
16 | push 新视图推出旧视图 kCATransitionPush 是
17 | reveal 移开旧视图显示新视图 kCATransitionReveal 是
18 | 私有API 私有API只能通过字符串访问
19 | cube 立方体翻转效果 无 是
20 | oglFlip 翻转效果 无 是
21 | suckEffect 收缩效果 无 否
22 | rippleEffect 水滴波纹效果 无 否
23 | pageCurl 向上翻页效果 无 是
24 | pageUnCurl 向下翻页效果 无 是
25 | cameralIrisHollowOpen 摄像头打开效果 无 否
26 | cameraIrisHollowClose 摄像头关闭效果 无 否
27 | 另外对于支持方向设置的动画类型还包含子类型:
28 | 动画子类型 说明
29 | kCATransitionFromRight 从右侧转场
30 | kCATransitionFromLeft 从左侧转场
31 | kCATransitionFromTop 从顶部转场
32 | kCATransitionFromBottom 从底部转场
33 | */
34 |
35 | typedef NS_ENUM(NSInteger, SRTransitionAnimateType) {
36 | SRTransitionAnimateTypeFade = 0,
37 | SRTransitionAnimateTypeMoveIn,
38 | SRTransitionAnimateTypePush,
39 | SRTransitionAnimateTypeReveal,
40 | SRTransitionAnimateTypeCube,
41 | SRTransitionAnimateTypeOglFlip,
42 | SRTransitionAnimateTypeSuckEffect,
43 | SRTransitionAnimateTypeRippleEffect,
44 | SRTransitionAnimateTypePageCurl,
45 | SRTransitionAnimateTypePageUncurl,
46 | SRTransitionAnimateTypeCameraIrisHollowOpen,
47 | SRTransitionAnimateTypeCameraIrisHollowClose
48 | };
49 |
50 | #pragma mark - CycleAnimatorViewControllerDelegate代理 -
51 |
52 | @protocol CycleAnimatorViewControllerDelegate
53 |
54 | /// cell 被点击
55 | - (void)pictureCycleCellDidSelected:(NSInteger)itemTag;
56 |
57 | @end
58 |
59 |
60 | #pragma mark - CycleAnimatorViewController -
61 |
62 | @interface CycleAnimatorViewController : UIViewController
63 |
64 | //图片视图
65 | @property (nonatomic,strong)UIImageView *animatorImageView;
66 |
67 | //展示的图片数组
68 | @property (nonatomic,strong)NSArray *animatorImageList;
69 |
70 | //动画效果类型
71 | @property (nonatomic,assign)SRTransitionAnimateType animationType;
72 |
73 | // 轮播时间间隔,默认4秒
74 | @property (nonatomic, assign) NSUInteger cycleTimeInterval;
75 |
76 | // delegate
77 | @property (nonatomic, assign) id delegate;
78 |
79 | //是否限制动画播放过程中,无法进行页面切换,默认为false
80 | @property (nonatomic, assign) BOOL isLimitGestureWhenAnimating;
81 |
82 | @end
83 |
--------------------------------------------------------------------------------
/SDWebImage/SDWebImageDecoder.m:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * Created by james on 9/28/11.
6 | *
7 | * For the full copyright and license information, please view the LICENSE
8 | * file that was distributed with this source code.
9 | */
10 |
11 | #import "SDWebImageDecoder.h"
12 |
13 | @implementation UIImage (ForceDecode)
14 |
15 | + (UIImage *)decodedImageWithImage:(UIImage *)image {
16 | if (image.images) {
17 | // Do not decode animated images
18 | return image;
19 | }
20 |
21 | CGImageRef imageRef = image.CGImage;
22 | CGSize imageSize = CGSizeMake(CGImageGetWidth(imageRef), CGImageGetHeight(imageRef));
23 | CGRect imageRect = (CGRect){.origin = CGPointZero, .size = imageSize};
24 |
25 | CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
26 | CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);
27 |
28 | int infoMask = (bitmapInfo & kCGBitmapAlphaInfoMask);
29 | BOOL anyNonAlpha = (infoMask == kCGImageAlphaNone ||
30 | infoMask == kCGImageAlphaNoneSkipFirst ||
31 | infoMask == kCGImageAlphaNoneSkipLast);
32 |
33 | // CGBitmapContextCreate doesn't support kCGImageAlphaNone with RGB.
34 | // https://developer.apple.com/library/mac/#qa/qa1037/_index.html
35 | if (infoMask == kCGImageAlphaNone && CGColorSpaceGetNumberOfComponents(colorSpace) > 1) {
36 | // Unset the old alpha info.
37 | bitmapInfo &= ~kCGBitmapAlphaInfoMask;
38 |
39 | // Set noneSkipFirst.
40 | bitmapInfo |= kCGImageAlphaNoneSkipFirst;
41 | }
42 | // Some PNGs tell us they have alpha but only 3 components. Odd.
43 | else if (!anyNonAlpha && CGColorSpaceGetNumberOfComponents(colorSpace) == 3) {
44 | // Unset the old alpha info.
45 | bitmapInfo &= ~kCGBitmapAlphaInfoMask;
46 | bitmapInfo |= kCGImageAlphaPremultipliedFirst;
47 | }
48 |
49 | // It calculates the bytes-per-row based on the bitsPerComponent and width arguments.
50 | CGContextRef context = CGBitmapContextCreate(NULL,
51 | imageSize.width,
52 | imageSize.height,
53 | CGImageGetBitsPerComponent(imageRef),
54 | 0,
55 | colorSpace,
56 | bitmapInfo);
57 | CGColorSpaceRelease(colorSpace);
58 |
59 | // If failed, return undecompressed image
60 | if (!context) return image;
61 |
62 | CGContextDrawImage(context, imageRect, imageRef);
63 | CGImageRef decompressedImageRef = CGBitmapContextCreateImage(context);
64 |
65 | CGContextRelease(context);
66 |
67 | UIImage *decompressedImage = [UIImage imageWithCGImage:decompressedImageRef scale:image.scale orientation:image.imageOrientation];
68 | CGImageRelease(decompressedImageRef);
69 | return decompressedImage;
70 | }
71 |
72 | @end
73 |
--------------------------------------------------------------------------------
/SDWebImage/SDWebImageDownloaderOperation.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import
10 | #import "SDWebImageDownloader.h"
11 | #import "SDWebImageOperation.h"
12 |
13 | extern NSString *const SDWebImageDownloadStartNotification;
14 | extern NSString *const SDWebImageDownloadReceiveResponseNotification;
15 | extern NSString *const SDWebImageDownloadStopNotification;
16 | extern NSString *const SDWebImageDownloadFinishNotification;
17 |
18 | @interface SDWebImageDownloaderOperation : NSOperation
19 |
20 | /**
21 | * The request used by the operation's connection.
22 | */
23 | @property (strong, nonatomic, readonly) NSURLRequest *request;
24 |
25 |
26 | @property (assign, nonatomic) BOOL shouldDecompressImages;
27 |
28 | /**
29 | * Whether the URL connection should consult the credential storage for authenticating the connection. `YES` by default.
30 | *
31 | * This is the value that is returned in the `NSURLConnectionDelegate` method `-connectionShouldUseCredentialStorage:`.
32 | */
33 | @property (nonatomic, assign) BOOL shouldUseCredentialStorage;
34 |
35 | /**
36 | * The credential used for authentication challenges in `-connection:didReceiveAuthenticationChallenge:`.
37 | *
38 | * This will be overridden by any shared credentials that exist for the username or password of the request URL, if present.
39 | */
40 | @property (nonatomic, strong) NSURLCredential *credential;
41 |
42 | /**
43 | * The SDWebImageDownloaderOptions for the receiver.
44 | */
45 | @property (assign, nonatomic, readonly) SDWebImageDownloaderOptions options;
46 |
47 | /**
48 | * The expected size of data.
49 | */
50 | @property (assign, nonatomic) NSInteger expectedSize;
51 |
52 | /**
53 | * The response returned by the operation's connection.
54 | */
55 | @property (strong, nonatomic) NSURLResponse *response;
56 |
57 | /**
58 | * Initializes a `SDWebImageDownloaderOperation` object
59 | *
60 | * @see SDWebImageDownloaderOperation
61 | *
62 | * @param request the URL request
63 | * @param options downloader options
64 | * @param progressBlock the block executed when a new chunk of data arrives.
65 | * @note the progress block is executed on a background queue
66 | * @param completedBlock the block executed when the download is done.
67 | * @note the completed block is executed on the main queue for success. If errors are found, there is a chance the block will be executed on a background queue
68 | * @param cancelBlock the block executed if the download (operation) is cancelled
69 | *
70 | * @return the initialized instance
71 | */
72 | - (id)initWithRequest:(NSURLRequest *)request
73 | options:(SDWebImageDownloaderOptions)options
74 | progress:(SDWebImageDownloaderProgressBlock)progressBlock
75 | completed:(SDWebImageDownloaderCompletedBlock)completedBlock
76 | cancelled:(SDWebImageNoParamsBlock)cancelBlock;
77 |
78 | @end
79 |
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Base.lproj/LaunchScreen.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
20 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/SDWebImage/UIImage+MultiFormat.m:
--------------------------------------------------------------------------------
1 | //
2 | // UIImage+MultiFormat.m
3 | // SDWebImage
4 | //
5 | // Created by Olivier Poitrey on 07/06/13.
6 | // Copyright (c) 2013 Dailymotion. All rights reserved.
7 | //
8 |
9 | #import "UIImage+MultiFormat.h"
10 | #import "UIImage+GIF.h"
11 | #import "NSData+ImageContentType.h"
12 | #import
13 |
14 | #ifdef SD_WEBP
15 | #import "UIImage+WebP.h"
16 | #endif
17 |
18 | @implementation UIImage (MultiFormat)
19 |
20 | + (UIImage *)sd_imageWithData:(NSData *)data {
21 | if (!data) {
22 | return nil;
23 | }
24 |
25 | UIImage *image;
26 | NSString *imageContentType = [NSData sd_contentTypeForImageData:data];
27 | if ([imageContentType isEqualToString:@"image/gif"]) {
28 | image = [UIImage sd_animatedGIFWithData:data];
29 | }
30 | #ifdef SD_WEBP
31 | else if ([imageContentType isEqualToString:@"image/webp"])
32 | {
33 | image = [UIImage sd_imageWithWebPData:data];
34 | }
35 | #endif
36 | else {
37 | image = [[UIImage alloc] initWithData:data];
38 | UIImageOrientation orientation = [self sd_imageOrientationFromImageData:data];
39 | if (orientation != UIImageOrientationUp) {
40 | image = [UIImage imageWithCGImage:image.CGImage
41 | scale:image.scale
42 | orientation:orientation];
43 | }
44 | }
45 |
46 |
47 | return image;
48 | }
49 |
50 |
51 | +(UIImageOrientation)sd_imageOrientationFromImageData:(NSData *)imageData {
52 | UIImageOrientation result = UIImageOrientationUp;
53 | CGImageSourceRef imageSource = CGImageSourceCreateWithData((__bridge CFDataRef)imageData, NULL);
54 | if (imageSource) {
55 | CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL);
56 | if (properties) {
57 | CFTypeRef val;
58 | int exifOrientation;
59 | val = CFDictionaryGetValue(properties, kCGImagePropertyOrientation);
60 | if (val) {
61 | CFNumberGetValue(val, kCFNumberIntType, &exifOrientation);
62 | result = [self sd_exifOrientationToiOSOrientation:exifOrientation];
63 | } // else - if it's not set it remains at up
64 | CFRelease((CFTypeRef) properties);
65 | } else {
66 | //NSLog(@"NO PROPERTIES, FAIL");
67 | }
68 | CFRelease(imageSource);
69 | }
70 | return result;
71 | }
72 |
73 | #pragma mark EXIF orientation tag converter
74 | // Convert an EXIF image orientation to an iOS one.
75 | // reference see here: http://sylvana.net/jpegcrop/exif_orientation.html
76 | + (UIImageOrientation) sd_exifOrientationToiOSOrientation:(int)exifOrientation {
77 | UIImageOrientation orientation = UIImageOrientationUp;
78 | switch (exifOrientation) {
79 | case 1:
80 | orientation = UIImageOrientationUp;
81 | break;
82 |
83 | case 3:
84 | orientation = UIImageOrientationDown;
85 | break;
86 |
87 | case 8:
88 | orientation = UIImageOrientationLeft;
89 | break;
90 |
91 | case 6:
92 | orientation = UIImageOrientationRight;
93 | break;
94 |
95 | case 2:
96 | orientation = UIImageOrientationUpMirrored;
97 | break;
98 |
99 | case 4:
100 | orientation = UIImageOrientationDownMirrored;
101 | break;
102 |
103 | case 5:
104 | orientation = UIImageOrientationLeftMirrored;
105 | break;
106 |
107 | case 7:
108 | orientation = UIImageOrientationRightMirrored;
109 | break;
110 | default:
111 | break;
112 | }
113 | return orientation;
114 | }
115 |
116 |
117 |
118 | @end
119 |
--------------------------------------------------------------------------------
/SDWebImage/SDWebImagePrefetcher.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import
10 | #import "SDWebImageManager.h"
11 |
12 | @class SDWebImagePrefetcher;
13 |
14 | @protocol SDWebImagePrefetcherDelegate
15 |
16 | @optional
17 |
18 | /**
19 | * Called when an image was prefetched.
20 | *
21 | * @param imagePrefetcher The current image prefetcher
22 | * @param imageURL The image url that was prefetched
23 | * @param finishedCount The total number of images that were prefetched (successful or not)
24 | * @param totalCount The total number of images that were to be prefetched
25 | */
26 | - (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didPrefetchURL:(NSURL *)imageURL finishedCount:(NSUInteger)finishedCount totalCount:(NSUInteger)totalCount;
27 |
28 | /**
29 | * Called when all images are prefetched.
30 | * @param imagePrefetcher The current image prefetcher
31 | * @param totalCount The total number of images that were prefetched (whether successful or not)
32 | * @param skippedCount The total number of images that were skipped
33 | */
34 | - (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didFinishWithTotalCount:(NSUInteger)totalCount skippedCount:(NSUInteger)skippedCount;
35 |
36 | @end
37 |
38 | typedef void(^SDWebImagePrefetcherProgressBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfTotalUrls);
39 | typedef void(^SDWebImagePrefetcherCompletionBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfSkippedUrls);
40 |
41 | /**
42 | * Prefetch some URLs in the cache for future use. Images are downloaded in low priority.
43 | */
44 | @interface SDWebImagePrefetcher : NSObject
45 |
46 | /**
47 | * The web image manager
48 | */
49 | @property (strong, nonatomic, readonly) SDWebImageManager *manager;
50 |
51 | /**
52 | * Maximum number of URLs to prefetch at the same time. Defaults to 3.
53 | */
54 | @property (nonatomic, assign) NSUInteger maxConcurrentDownloads;
55 |
56 | /**
57 | * SDWebImageOptions for prefetcher. Defaults to SDWebImageLowPriority.
58 | */
59 | @property (nonatomic, assign) SDWebImageOptions options;
60 |
61 | /**
62 | * Queue options for Prefetcher. Defaults to Main Queue.
63 | */
64 | @property (nonatomic, assign) dispatch_queue_t prefetcherQueue;
65 |
66 | @property (weak, nonatomic) id delegate;
67 |
68 | /**
69 | * Return the global image prefetcher instance.
70 | */
71 | + (SDWebImagePrefetcher *)sharedImagePrefetcher;
72 |
73 | /**
74 | * Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching,
75 | * currently one image is downloaded at a time,
76 | * and skips images for failed downloads and proceed to the next image in the list
77 | *
78 | * @param urls list of URLs to prefetch
79 | */
80 | - (void)prefetchURLs:(NSArray *)urls;
81 |
82 | /**
83 | * Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching,
84 | * currently one image is downloaded at a time,
85 | * and skips images for failed downloads and proceed to the next image in the list
86 | *
87 | * @param urls list of URLs to prefetch
88 | * @param progressBlock block to be called when progress updates;
89 | * first parameter is the number of completed (successful or not) requests,
90 | * second parameter is the total number of images originally requested to be prefetched
91 | * @param completionBlock block to be called when prefetching is completed
92 | * first param is the number of completed (successful or not) requests,
93 | * second parameter is the number of skipped requests
94 | */
95 | - (void)prefetchURLs:(NSArray *)urls progress:(SDWebImagePrefetcherProgressBlock)progressBlock completed:(SDWebImagePrefetcherCompletionBlock)completionBlock;
96 |
97 | /**
98 | * Remove and cancel queued list
99 | */
100 | - (void)cancelPrefetching;
101 |
102 |
103 | @end
104 |
--------------------------------------------------------------------------------
/CycleView_OC_Demo/CycleView_OC_Demo/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/SDWebImage/UIImageView+HighlightedWebCache.m:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import "UIImageView+HighlightedWebCache.h"
10 | #import "UIView+WebCacheOperation.h"
11 |
12 | #define UIImageViewHighlightedWebCacheOperationKey @"highlightedImage"
13 |
14 | @implementation UIImageView (HighlightedWebCache)
15 |
16 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url {
17 | [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:nil];
18 | }
19 |
20 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options {
21 | [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:nil];
22 | }
23 |
24 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock {
25 | [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:completedBlock];
26 | }
27 |
28 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
29 | [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:completedBlock];
30 | }
31 |
32 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock {
33 | [self sd_cancelCurrentHighlightedImageLoad];
34 |
35 | if (url) {
36 | __weak __typeof(self)wself = self;
37 | id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
38 | if (!wself) return;
39 | dispatch_main_sync_safe (^
40 | {
41 | if (!wself) return;
42 | if (image) {
43 | wself.highlightedImage = image;
44 | [wself setNeedsLayout];
45 | }
46 | if (completedBlock && finished) {
47 | completedBlock(image, error, cacheType, url);
48 | }
49 | });
50 | }];
51 | [self sd_setImageLoadOperation:operation forKey:UIImageViewHighlightedWebCacheOperationKey];
52 | } else {
53 | dispatch_main_async_safe(^{
54 | NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
55 | if (completedBlock) {
56 | completedBlock(nil, error, SDImageCacheTypeNone, url);
57 | }
58 | });
59 | }
60 | }
61 |
62 | - (void)sd_cancelCurrentHighlightedImageLoad {
63 | [self sd_cancelImageLoadOperationWithKey:UIImageViewHighlightedWebCacheOperationKey];
64 | }
65 |
66 | @end
67 |
68 |
69 | @implementation UIImageView (HighlightedWebCacheDeprecated)
70 |
71 | - (void)setHighlightedImageWithURL:(NSURL *)url {
72 | [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:nil];
73 | }
74 |
75 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options {
76 | [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:nil];
77 | }
78 |
79 | - (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock {
80 | [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
81 | if (completedBlock) {
82 | completedBlock(image, error, cacheType);
83 | }
84 | }];
85 | }
86 |
87 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
88 | [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
89 | if (completedBlock) {
90 | completedBlock(image, error, cacheType);
91 | }
92 | }];
93 | }
94 |
95 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock {
96 | [self sd_setHighlightedImageWithURL:url options:0 progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
97 | if (completedBlock) {
98 | completedBlock(image, error, cacheType);
99 | }
100 | }];
101 | }
102 |
103 | - (void)cancelCurrentHighlightedImageLoad {
104 | [self sd_cancelCurrentHighlightedImageLoad];
105 | }
106 |
107 | @end
108 |
--------------------------------------------------------------------------------
/SDWebImage/UIImageView+HighlightedWebCache.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import
10 | #import "SDWebImageCompat.h"
11 | #import "SDWebImageManager.h"
12 |
13 | /**
14 | * Integrates SDWebImage async downloading and caching of remote images with UIImageView for highlighted state.
15 | */
16 | @interface UIImageView (HighlightedWebCache)
17 |
18 | /**
19 | * Set the imageView `highlightedImage` with an `url`.
20 | *
21 | * The download is asynchronous and cached.
22 | *
23 | * @param url The url for the image.
24 | */
25 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url;
26 |
27 | /**
28 | * Set the imageView `highlightedImage` with an `url` and custom options.
29 | *
30 | * The download is asynchronous and cached.
31 | *
32 | * @param url The url for the image.
33 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
34 | */
35 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options;
36 |
37 | /**
38 | * Set the imageView `highlightedImage` with an `url`.
39 | *
40 | * The download is asynchronous and cached.
41 | *
42 | * @param url The url for the image.
43 | * @param completedBlock A block called when operation has been completed. This block has no return value
44 | * and takes the requested UIImage as first parameter. In case of error the image parameter
45 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
46 | * indicating if the image was retrived from the local cache or from the network.
47 | * The fourth parameter is the original image url.
48 | */
49 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock;
50 |
51 | /**
52 | * Set the imageView `highlightedImage` with an `url` and custom options.
53 | *
54 | * The download is asynchronous and cached.
55 | *
56 | * @param url The url for the image.
57 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
58 | * @param completedBlock A block called when operation has been completed. This block has no return value
59 | * and takes the requested UIImage as first parameter. In case of error the image parameter
60 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
61 | * indicating if the image was retrived from the local cache or from the network.
62 | * The fourth parameter is the original image url.
63 | */
64 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
65 |
66 | /**
67 | * Set the imageView `highlightedImage` with an `url` and custom options.
68 | *
69 | * The download is asynchronous and cached.
70 | *
71 | * @param url The url for the image.
72 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
73 | * @param progressBlock A block called while image is downloading
74 | * @param completedBlock A block called when operation has been completed. This block has no return value
75 | * and takes the requested UIImage as first parameter. In case of error the image parameter
76 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
77 | * indicating if the image was retrived from the local cache or from the network.
78 | * The fourth parameter is the original image url.
79 | */
80 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock;
81 |
82 | /**
83 | * Cancel the current download
84 | */
85 | - (void)sd_cancelCurrentHighlightedImageLoad;
86 |
87 | @end
88 |
89 |
90 | @interface UIImageView (HighlightedWebCacheDeprecated)
91 |
92 | - (void)setHighlightedImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:`");
93 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:`");
94 | - (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:completed:`");
95 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:completed:`");
96 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:progress:completed:`");
97 |
98 | - (void)cancelCurrentHighlightedImageLoad __deprecated_msg("Use `sd_cancelCurrentHighlightedImageLoad`");
99 |
100 | @end
101 |
--------------------------------------------------------------------------------
/SDWebImage/UIImage+GIF.m:
--------------------------------------------------------------------------------
1 | //
2 | // UIImage+GIF.m
3 | // LBGIFImage
4 | //
5 | // Created by Laurin Brandner on 06.01.12.
6 | // Copyright (c) 2012 __MyCompanyName__. All rights reserved.
7 | //
8 |
9 | #import "UIImage+GIF.h"
10 | #import
11 |
12 | @implementation UIImage (GIF)
13 |
14 | + (UIImage *)sd_animatedGIFWithData:(NSData *)data {
15 | if (!data) {
16 | return nil;
17 | }
18 |
19 | CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL);
20 |
21 | size_t count = CGImageSourceGetCount(source);
22 |
23 | UIImage *animatedImage;
24 |
25 | if (count <= 1) {
26 | animatedImage = [[UIImage alloc] initWithData:data];
27 | }
28 | else {
29 | NSMutableArray *images = [NSMutableArray array];
30 |
31 | NSTimeInterval duration = 0.0f;
32 |
33 | for (size_t i = 0; i < count; i++) {
34 | CGImageRef image = CGImageSourceCreateImageAtIndex(source, i, NULL);
35 |
36 | duration += [self sd_frameDurationAtIndex:i source:source];
37 |
38 | [images addObject:[UIImage imageWithCGImage:image scale:[UIScreen mainScreen].scale orientation:UIImageOrientationUp]];
39 |
40 | CGImageRelease(image);
41 | }
42 |
43 | if (!duration) {
44 | duration = (1.0f / 10.0f) * count;
45 | }
46 |
47 | animatedImage = [UIImage animatedImageWithImages:images duration:duration];
48 | }
49 |
50 | CFRelease(source);
51 |
52 | return animatedImage;
53 | }
54 |
55 | + (float)sd_frameDurationAtIndex:(NSUInteger)index source:(CGImageSourceRef)source {
56 | float frameDuration = 0.1f;
57 | CFDictionaryRef cfFrameProperties = CGImageSourceCopyPropertiesAtIndex(source, index, nil);
58 | NSDictionary *frameProperties = (__bridge NSDictionary *)cfFrameProperties;
59 | NSDictionary *gifProperties = frameProperties[(NSString *)kCGImagePropertyGIFDictionary];
60 |
61 | NSNumber *delayTimeUnclampedProp = gifProperties[(NSString *)kCGImagePropertyGIFUnclampedDelayTime];
62 | if (delayTimeUnclampedProp) {
63 | frameDuration = [delayTimeUnclampedProp floatValue];
64 | }
65 | else {
66 |
67 | NSNumber *delayTimeProp = gifProperties[(NSString *)kCGImagePropertyGIFDelayTime];
68 | if (delayTimeProp) {
69 | frameDuration = [delayTimeProp floatValue];
70 | }
71 | }
72 |
73 | // Many annoying ads specify a 0 duration to make an image flash as quickly as possible.
74 | // We follow Firefox's behavior and use a duration of 100 ms for any frames that specify
75 | // a duration of <= 10 ms. See and
76 | // for more information.
77 |
78 | if (frameDuration < 0.011f) {
79 | frameDuration = 0.100f;
80 | }
81 |
82 | CFRelease(cfFrameProperties);
83 | return frameDuration;
84 | }
85 |
86 | + (UIImage *)sd_animatedGIFNamed:(NSString *)name {
87 | CGFloat scale = [UIScreen mainScreen].scale;
88 |
89 | if (scale > 1.0f) {
90 | NSString *retinaPath = [[NSBundle mainBundle] pathForResource:[name stringByAppendingString:@"@2x"] ofType:@"gif"];
91 |
92 | NSData *data = [NSData dataWithContentsOfFile:retinaPath];
93 |
94 | if (data) {
95 | return [UIImage sd_animatedGIFWithData:data];
96 | }
97 |
98 | NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"gif"];
99 |
100 | data = [NSData dataWithContentsOfFile:path];
101 |
102 | if (data) {
103 | return [UIImage sd_animatedGIFWithData:data];
104 | }
105 |
106 | return [UIImage imageNamed:name];
107 | }
108 | else {
109 | NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"gif"];
110 |
111 | NSData *data = [NSData dataWithContentsOfFile:path];
112 |
113 | if (data) {
114 | return [UIImage sd_animatedGIFWithData:data];
115 | }
116 |
117 | return [UIImage imageNamed:name];
118 | }
119 | }
120 |
121 | - (UIImage *)sd_animatedImageByScalingAndCroppingToSize:(CGSize)size {
122 | if (CGSizeEqualToSize(self.size, size) || CGSizeEqualToSize(size, CGSizeZero)) {
123 | return self;
124 | }
125 |
126 | CGSize scaledSize = size;
127 | CGPoint thumbnailPoint = CGPointZero;
128 |
129 | CGFloat widthFactor = size.width / self.size.width;
130 | CGFloat heightFactor = size.height / self.size.height;
131 | CGFloat scaleFactor = (widthFactor > heightFactor) ? widthFactor : heightFactor;
132 | scaledSize.width = self.size.width * scaleFactor;
133 | scaledSize.height = self.size.height * scaleFactor;
134 |
135 | if (widthFactor > heightFactor) {
136 | thumbnailPoint.y = (size.height - scaledSize.height) * 0.5;
137 | }
138 | else if (widthFactor < heightFactor) {
139 | thumbnailPoint.x = (size.width - scaledSize.width) * 0.5;
140 | }
141 |
142 | NSMutableArray *scaledImages = [NSMutableArray array];
143 |
144 | UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
145 |
146 | for (UIImage *image in self.images) {
147 | [image drawInRect:CGRectMake(thumbnailPoint.x, thumbnailPoint.y, scaledSize.width, scaledSize.height)];
148 | UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
149 |
150 | [scaledImages addObject:newImage];
151 | }
152 |
153 | UIGraphicsEndImageContext();
154 |
155 | return [UIImage animatedImageWithImages:scaledImages duration:self.duration];
156 | }
157 |
158 | @end
159 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # CycleView_OC
2 |
3 | * The easiest way to use infinite-loop-view,New network image matching
4 | * 用法最简单的无限循环的图片轮播器,新增了网络图片的适配。
5 |
6 | ## Requirements
7 |
8 | * iOS 6.0+
9 |
10 | ## Installation
11 |
12 | ### CocoaPods
13 |
14 | CocoaPods 0.36 adds supports for Swift and embedded frameworks. You can install it with the following command:
15 |
16 | ```bash
17 | $ gem install cocoapods
18 | ```
19 |
20 | To integrate CycleView_OC into your Xcode project using CocoaPods, specify it in your `Podfile`:
21 |
22 | ```
23 | platform :ios, '5.0'
24 | use_frameworks!
25 |
26 | pod 'CycleView_OC'
27 | ```
28 |
29 | Then, run the following command:
30 |
31 | ```bash
32 | $ pod install
33 | ```
34 |
35 | You should open the `{Project}.xcworkspace` instead of the `{Project}.xcodeproj` after you installed anything from CocoaPods.
36 |
37 | For more information about how to use CocoaPods, I suggest [this tutorial](http://www.raywenderlich.com/64546/introduction-to-cocoapods-2).
38 |
39 | ## 如何使用CycleView_OC
40 | * cocoapods导入:`pod 'CycleView_OC'`
41 | * 手动导入:
42 | * 将`CycleView_OC/Classes`文件夹中的所有文件拽入项目中
43 | * 导入主头文件:`#import "CycleView_OC.h"`
44 |
45 | ## Usage
46 | ### Regular
47 | ```
48 | //Regular CycleView
49 | //普通的图片轮播器
50 | #import "CycleViewController.h"
51 | //此处的协议用于监听图片被点击的事件。
52 | @interface CycleViewController ()
53 |
54 | @end
55 |
56 | @implementation CycleViewController
57 |
58 | - (void)viewDidLoad {
59 | [super viewDidLoad];
60 |
61 | NSMutableArray *arrayM = [NSMutableArray array];
62 |
63 | for (int i = 0; i < 5; ++i) {
64 |
65 | NSString *imageName = [NSString stringWithFormat:@"%02d.jpg", i + 1];
66 | [arrayM addObject:[UIImage imageNamed:imageName]];
67 | }
68 | //传入图片列表
69 | self.cycleImageList = arrayM;
70 | //也可以加载URL数组
71 | self.netImage = YES;
72 | self.cycleImageUrls = @[@"http://pic2.sc.chinaz.com/files/pic/pic9/201512/apic16892.jpg",@"http://pic14.nipic.com/20110522/7411759_164157418126_2.jpg",@"http://pic.nipic.com/2007-11-09/2007119122519868_2.jpg",@"http://pic24.nipic.com/20121022/9252150_193011306000_2.jpg"];
73 | }
74 |
75 | ///通过重写这个代理方法,即可进行点击图片后的交互处理.
76 | //itemTag为图片的tag值,默认从0开始递增。
77 | - (void)pictureCycleCellDidSelected:(NSInteger)itemTag{
78 | NSLog(@"被选中的item的tag值:%zd", itemTag);
79 | }
80 |
81 | ```
82 |
83 | ### Special
84 | ```
85 | //继承 CycleAnimatorViewController
86 | @interface CycleViewController : CycleAnimatorViewController
87 | ```
88 |
89 | * ViewDidLoad中的处理
90 | ```
91 | - (void)viewDidLoad {
92 | [super viewDidLoad];
93 |
94 | NSMutableArray *arrayM = [NSMutableArray array];
95 |
96 | for (int i = 0; i < 5; ++i) {
97 |
98 | NSString *imageName = [NSString stringWithFormat:@"%02d.jpg", i + 1];
99 | [arrayM addObject:[UIImage imageNamed:imageName]];
100 | }
101 |
102 | #pragma mark - required
103 | //You should set the size of the view
104 | //设置视图的大小
105 | [self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
106 |
107 | //You should set the image array
108 | //设置图片数组
109 | self.animatorImageList = arrayM;
110 |
111 | #pragma mark - optional
112 | //you can modify the animation effect by enumeration type
113 | //可以通过枚举类型,修改动画效果
114 | self.animationType = SRTransitionAnimateTypeRippleEffect;
115 |
116 | //You can set the picture carousel time interval
117 | //可以设置图片轮播的时间间隔
118 | self.cycleTimeInterval = 4;
119 |
120 | //You can set whether to limit the page switching in the animation implementation process
121 | //可以设置是否限制在动画执行过程中进行页面切换
122 | self.isLimitGestureWhenAnimating = NO;
123 |
124 | //you can change image's contentMode
125 | //可以设置图片填充模式
126 | self.animatorImageView.contentMode = UIViewContentModeScaleToFill;
127 | }
128 | ```
129 |
130 | * 在需要使用这个控制器的地方进行如下设置:
131 | ```
132 | CycleViewController *cycleView = [[CycleViewController alloc] init]; // 创建图片轮转
133 | [self addChildViewController:cycleView];// 添加控制
134 | cycleView.delegate = self;//设置代理
135 | ```
136 | * 满足代理协议``
137 | * 通过重写这个代理方法,即可进行点击图片后的交互处理.
138 | ```
139 | - (void)pictureCycleCellDidSelected:(NSInteger)itemTag{
140 | NSLog(@"被选中的item的tag值:%zd", itemTag);
141 | }
142 |
143 | ```
144 |
145 |
146 | ##Screenshot
147 |
148 | ```
149 | 常规图片轮播器
150 | ```
151 | * 
152 |
153 | ```
154 | 立体旋转效果
155 | ```
156 | * 
157 |
158 | ```
159 | 淡入淡出效果
160 | ```
161 | * 
162 |
163 | ```
164 | 平面翻转效果
165 | ```
166 | * 
167 |
168 | ```
169 | 翻页效果
170 | ```
171 | * 
172 |
173 | ```
174 | 反向翻页效果
175 | ```
176 | * 
177 |
178 | ```
179 | 横向推出效果
180 | ```
181 | * 
182 |
183 | ```
184 | 从上层抽出效果
185 | ```
186 | * 
187 |
188 | ```
189 | 水滴效果
190 | ```
191 | * 
192 |
193 | ```
194 | 从角落收起效果
195 | ```
196 | * 
197 |
198 |
--------------------------------------------------------------------------------
/CycleView_OC.podspec:
--------------------------------------------------------------------------------
1 | #
2 | # Be sure to run `pod spec lint CycleView_OC.podspec' to ensure this is a
3 | # valid spec and to remove all comments including this before submitting the spec.
4 | #
5 | # To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
6 | # To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
7 | #
8 |
9 | Pod::Spec.new do |s|
10 |
11 | # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
12 | #
13 | # These will help people to find your library, and whilst it
14 | # can feel like a chore to fill in it's definitely to your advantage. The
15 | # summary should be tweet-length, and the description more in depth.
16 | #
17 |
18 | s.name = "CycleView_OC"
19 | s.version = "1.1.0"
20 | s.summary = "用法最简单的无限循环的图片轮播器,使用OC实现,更加便于大家的使用。The easiest way to use infinite-loop-view."
21 |
22 | s.description = <<-DESC
23 | 简化我们的日常开发,最常用,也是适用性最广的图片轮播期框架。Simplify our daily development, the most commonly used, is also the most widely applicability pictures。
24 |
25 | * Think: Why did you write this? What is the focus? What does it do?
26 | * CocoaPods will be using this to generate tags, and improve search results.
27 | * Try to keep it short, snappy and to the point.
28 | * Finally, don't worry about the indent, CocoaPods strips it!
29 | DESC
30 |
31 | s.homepage = "https://github.com/SarielTang/CycleView_OC"
32 | # s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"
33 |
34 |
35 | # ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
36 | #
37 | # Licensing your code is important. See http://choosealicense.com for more info.
38 | # CocoaPods will detect a license file if there is a named LICENSE*
39 | # Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
40 | #
41 |
42 | s.license = "MIT"
43 | # s.license = { :type => "MIT", :file => "FILE_LICENSE" }
44 |
45 |
46 | # ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
47 | #
48 | # Specify the authors of the library, with email addresses. Email addresses
49 | # of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
50 | # accepts just a name if you'd rather not provide an email address.
51 | #
52 | # Specify a social_media_url where others can refer to, for example a twitter
53 | # profile URL.
54 | #
55 |
56 | s.author = { "SarielTang" => "sarieltang@163.com" }
57 | # Or just: s.author = "汤晔"
58 | # s.authors = { "汤晔" => "524896762@qq.com" }
59 | # s.social_media_url = "http://twitter.com/汤晔"
60 |
61 | # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
62 | #
63 | # If this Pod runs only on iOS or OS X, then specify the platform and
64 | # the deployment target. You can optionally include the target after the platform.
65 | #
66 |
67 | s.platform = :ios
68 | # s.platform = :ios, "5.0"
69 |
70 | # When using multiple platforms
71 | # s.ios.deployment_target = "5.0"
72 | # s.osx.deployment_target = "10.7"
73 |
74 |
75 | # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
76 | #
77 | # Specify the location from where the source should be retrieved.
78 | # Supports git, hg, bzr, svn and HTTP.
79 | #
80 |
81 | s.source = { :git => "https://github.com/SarielTang/CycleView_OC.git", :tag => s.version }
82 |
83 |
84 | # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
85 | #
86 | # CocoaPods is smart about how it includes source code. For source files
87 | # giving a folder will include any swift, h, m, mm, c & cpp files.
88 | # For header files it will include any header in the folder.
89 | # Not including the public_header_files will make all headers public.
90 | #
91 |
92 | s.source_files = "Classes", "Classes/*.{h,m}"
93 | # s.exclude_files = "Classes/Exclude"
94 |
95 | # s.public_header_files = "Classes/**/*.h"
96 |
97 |
98 | # ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
99 | #
100 | # A list of resources included with the Pod. These are copied into the
101 | # target bundle with a build phase script. Anything else will be cleaned.
102 | # You can preserve files from being cleaned, please don't preserve
103 | # non-essential files like tests, examples and documentation.
104 | #
105 |
106 | # s.resource = "icon.png"
107 | # s.resources = "Resources/*.png"
108 |
109 | # s.preserve_paths = "FilesToSave", "MoreFilesToSave"
110 |
111 |
112 | # ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
113 | #
114 | # Link your library with frameworks, or libraries. Libraries do not include
115 | # the lib prefix of their name.
116 | #
117 |
118 | # s.framework = "SomeFramework"
119 | # s.frameworks = "SomeFramework", "AnotherFramework"
120 |
121 | # s.library = "iconv"
122 | # s.libraries = "iconv", "xml2"
123 |
124 |
125 | # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
126 | #
127 | # If your library depends on compiler flags you can set them in the xcconfig hash
128 | # where they will only apply to your library. If you depend on other Podspecs
129 | # you can include multiple dependencies to ensure it works.
130 |
131 | s.requires_arc = true
132 |
133 | # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
134 | # s.dependency "JSONKit", "~> 1.4"
135 |
136 | end
137 |
--------------------------------------------------------------------------------
/SDWebImage/SDWebImagePrefetcher.m:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import "SDWebImagePrefetcher.h"
10 |
11 | #if (!defined(DEBUG) && !defined (SD_VERBOSE)) || defined(SD_LOG_NONE)
12 | #define NSLog(...)
13 | #endif
14 |
15 | @interface SDWebImagePrefetcher ()
16 |
17 | @property (strong, nonatomic) SDWebImageManager *manager;
18 | @property (strong, nonatomic) NSArray *prefetchURLs;
19 | @property (assign, nonatomic) NSUInteger requestedCount;
20 | @property (assign, nonatomic) NSUInteger skippedCount;
21 | @property (assign, nonatomic) NSUInteger finishedCount;
22 | @property (assign, nonatomic) NSTimeInterval startedTime;
23 | @property (copy, nonatomic) SDWebImagePrefetcherCompletionBlock completionBlock;
24 | @property (copy, nonatomic) SDWebImagePrefetcherProgressBlock progressBlock;
25 |
26 | @end
27 |
28 | @implementation SDWebImagePrefetcher
29 |
30 | + (SDWebImagePrefetcher *)sharedImagePrefetcher {
31 | static dispatch_once_t once;
32 | static id instance;
33 | dispatch_once(&once, ^{
34 | instance = [self new];
35 | });
36 | return instance;
37 | }
38 |
39 | - (id)init {
40 | if ((self = [super init])) {
41 | _manager = [SDWebImageManager new];
42 | _options = SDWebImageLowPriority;
43 | _prefetcherQueue = dispatch_get_main_queue();
44 | self.maxConcurrentDownloads = 3;
45 | }
46 | return self;
47 | }
48 |
49 | - (void)setMaxConcurrentDownloads:(NSUInteger)maxConcurrentDownloads {
50 | self.manager.imageDownloader.maxConcurrentDownloads = maxConcurrentDownloads;
51 | }
52 |
53 | - (NSUInteger)maxConcurrentDownloads {
54 | return self.manager.imageDownloader.maxConcurrentDownloads;
55 | }
56 |
57 | - (void)startPrefetchingAtIndex:(NSUInteger)index {
58 | if (index >= self.prefetchURLs.count) return;
59 | self.requestedCount++;
60 | [self.manager downloadImageWithURL:self.prefetchURLs[index] options:self.options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
61 | if (!finished) return;
62 | self.finishedCount++;
63 |
64 | if (image) {
65 | if (self.progressBlock) {
66 | self.progressBlock(self.finishedCount,[self.prefetchURLs count]);
67 | }
68 | NSLog(@"Prefetched %@ out of %@", @(self.finishedCount), @(self.prefetchURLs.count));
69 | }
70 | else {
71 | if (self.progressBlock) {
72 | self.progressBlock(self.finishedCount,[self.prefetchURLs count]);
73 | }
74 | NSLog(@"Prefetched %@ out of %@ (Failed)", @(self.finishedCount), @(self.prefetchURLs.count));
75 |
76 | // Add last failed
77 | self.skippedCount++;
78 | }
79 | if ([self.delegate respondsToSelector:@selector(imagePrefetcher:didPrefetchURL:finishedCount:totalCount:)]) {
80 | [self.delegate imagePrefetcher:self
81 | didPrefetchURL:self.prefetchURLs[index]
82 | finishedCount:self.finishedCount
83 | totalCount:self.prefetchURLs.count
84 | ];
85 | }
86 | if (self.prefetchURLs.count > self.requestedCount) {
87 | dispatch_async(self.prefetcherQueue, ^{
88 | [self startPrefetchingAtIndex:self.requestedCount];
89 | });
90 | }
91 | else if (self.finishedCount == self.requestedCount) {
92 | [self reportStatus];
93 | if (self.completionBlock) {
94 | self.completionBlock(self.finishedCount, self.skippedCount);
95 | self.completionBlock = nil;
96 | }
97 | self.progressBlock = nil;
98 | }
99 | }];
100 | }
101 |
102 | - (void)reportStatus {
103 | NSUInteger total = [self.prefetchURLs count];
104 | NSLog(@"Finished prefetching (%@ successful, %@ skipped, timeElasped %.2f)", @(total - self.skippedCount), @(self.skippedCount), CFAbsoluteTimeGetCurrent() - self.startedTime);
105 | if ([self.delegate respondsToSelector:@selector(imagePrefetcher:didFinishWithTotalCount:skippedCount:)]) {
106 | [self.delegate imagePrefetcher:self
107 | didFinishWithTotalCount:(total - self.skippedCount)
108 | skippedCount:self.skippedCount
109 | ];
110 | }
111 | }
112 |
113 | - (void)prefetchURLs:(NSArray *)urls {
114 | [self prefetchURLs:urls progress:nil completed:nil];
115 | }
116 |
117 | - (void)prefetchURLs:(NSArray *)urls progress:(SDWebImagePrefetcherProgressBlock)progressBlock completed:(SDWebImagePrefetcherCompletionBlock)completionBlock {
118 | [self cancelPrefetching]; // Prevent duplicate prefetch request
119 | self.startedTime = CFAbsoluteTimeGetCurrent();
120 | self.prefetchURLs = urls;
121 | self.completionBlock = completionBlock;
122 | self.progressBlock = progressBlock;
123 |
124 | if(urls.count == 0){
125 | if(completionBlock){
126 | completionBlock(0,0);
127 | }
128 | }else{
129 | // Starts prefetching from the very first image on the list with the max allowed concurrency
130 | NSUInteger listCount = self.prefetchURLs.count;
131 | for (NSUInteger i = 0; i < self.maxConcurrentDownloads && self.requestedCount < listCount; i++) {
132 | [self startPrefetchingAtIndex:i];
133 | }
134 | }
135 | }
136 |
137 | - (void)cancelPrefetching {
138 | self.prefetchURLs = nil;
139 | self.skippedCount = 0;
140 | self.requestedCount = 0;
141 | self.finishedCount = 0;
142 | [self.manager cancelAll];
143 | }
144 |
145 | @end
146 |
--------------------------------------------------------------------------------
/SDWebImage/SDWebImageDownloader.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import
10 | #import "SDWebImageCompat.h"
11 | #import "SDWebImageOperation.h"
12 |
13 | typedef NS_OPTIONS(NSUInteger, SDWebImageDownloaderOptions) {
14 | SDWebImageDownloaderLowPriority = 1 << 0,
15 | SDWebImageDownloaderProgressiveDownload = 1 << 1,
16 |
17 | /**
18 | * By default, request prevent the of NSURLCache. With this flag, NSURLCache
19 | * is used with default policies.
20 | */
21 | SDWebImageDownloaderUseNSURLCache = 1 << 2,
22 |
23 | /**
24 | * Call completion block with nil image/imageData if the image was read from NSURLCache
25 | * (to be combined with `SDWebImageDownloaderUseNSURLCache`).
26 | */
27 |
28 | SDWebImageDownloaderIgnoreCachedResponse = 1 << 3,
29 | /**
30 | * In iOS 4+, continue the download of the image if the app goes to background. This is achieved by asking the system for
31 | * extra time in background to let the request finish. If the background task expires the operation will be cancelled.
32 | */
33 |
34 | SDWebImageDownloaderContinueInBackground = 1 << 4,
35 |
36 | /**
37 | * Handles cookies stored in NSHTTPCookieStore by setting
38 | * NSMutableURLRequest.HTTPShouldHandleCookies = YES;
39 | */
40 | SDWebImageDownloaderHandleCookies = 1 << 5,
41 |
42 | /**
43 | * Enable to allow untrusted SSL ceriticates.
44 | * Useful for testing purposes. Use with caution in production.
45 | */
46 | SDWebImageDownloaderAllowInvalidSSLCertificates = 1 << 6,
47 |
48 | /**
49 | * Put the image in the high priority queue.
50 | */
51 | SDWebImageDownloaderHighPriority = 1 << 7,
52 | };
53 |
54 | typedef NS_ENUM(NSInteger, SDWebImageDownloaderExecutionOrder) {
55 | /**
56 | * Default value. All download operations will execute in queue style (first-in-first-out).
57 | */
58 | SDWebImageDownloaderFIFOExecutionOrder,
59 |
60 | /**
61 | * All download operations will execute in stack style (last-in-first-out).
62 | */
63 | SDWebImageDownloaderLIFOExecutionOrder
64 | };
65 |
66 | extern NSString *const SDWebImageDownloadStartNotification;
67 | extern NSString *const SDWebImageDownloadStopNotification;
68 |
69 | typedef void(^SDWebImageDownloaderProgressBlock)(NSInteger receivedSize, NSInteger expectedSize);
70 |
71 | typedef void(^SDWebImageDownloaderCompletedBlock)(UIImage *image, NSData *data, NSError *error, BOOL finished);
72 |
73 | typedef NSDictionary *(^SDWebImageDownloaderHeadersFilterBlock)(NSURL *url, NSDictionary *headers);
74 |
75 | /**
76 | * Asynchronous downloader dedicated and optimized for image loading.
77 | */
78 | @interface SDWebImageDownloader : NSObject
79 |
80 | /**
81 | * Decompressing images that are downloaded and cached can improve peformance but can consume lot of memory.
82 | * Defaults to YES. Set this to NO if you are experiencing a crash due to excessive memory consumption.
83 | */
84 | @property (assign, nonatomic) BOOL shouldDecompressImages;
85 |
86 | @property (assign, nonatomic) NSInteger maxConcurrentDownloads;
87 |
88 | /**
89 | * Shows the current amount of downloads that still need to be downloaded
90 | */
91 | @property (readonly, nonatomic) NSUInteger currentDownloadCount;
92 |
93 |
94 | /**
95 | * The timeout value (in seconds) for the download operation. Default: 15.0.
96 | */
97 | @property (assign, nonatomic) NSTimeInterval downloadTimeout;
98 |
99 |
100 | /**
101 | * Changes download operations execution order. Default value is `SDWebImageDownloaderFIFOExecutionOrder`.
102 | */
103 | @property (assign, nonatomic) SDWebImageDownloaderExecutionOrder executionOrder;
104 |
105 | /**
106 | * Singleton method, returns the shared instance
107 | *
108 | * @return global shared instance of downloader class
109 | */
110 | + (SDWebImageDownloader *)sharedDownloader;
111 |
112 | /**
113 | * Set username
114 | */
115 | @property (strong, nonatomic) NSString *username;
116 |
117 | /**
118 | * Set password
119 | */
120 | @property (strong, nonatomic) NSString *password;
121 |
122 | /**
123 | * Set filter to pick headers for downloading image HTTP request.
124 | *
125 | * This block will be invoked for each downloading image request, returned
126 | * NSDictionary will be used as headers in corresponding HTTP request.
127 | */
128 | @property (nonatomic, copy) SDWebImageDownloaderHeadersFilterBlock headersFilter;
129 |
130 | /**
131 | * Set a value for a HTTP header to be appended to each download HTTP request.
132 | *
133 | * @param value The value for the header field. Use `nil` value to remove the header.
134 | * @param field The name of the header field to set.
135 | */
136 | - (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field;
137 |
138 | /**
139 | * Returns the value of the specified HTTP header field.
140 | *
141 | * @return The value associated with the header field field, or `nil` if there is no corresponding header field.
142 | */
143 | - (NSString *)valueForHTTPHeaderField:(NSString *)field;
144 |
145 | /**
146 | * Sets a subclass of `SDWebImageDownloaderOperation` as the default
147 | * `NSOperation` to be used each time SDWebImage constructs a request
148 | * operation to download an image.
149 | *
150 | * @param operationClass The subclass of `SDWebImageDownloaderOperation` to set
151 | * as default. Passing `nil` will revert to `SDWebImageDownloaderOperation`.
152 | */
153 | - (void)setOperationClass:(Class)operationClass;
154 |
155 | /**
156 | * Creates a SDWebImageDownloader async downloader instance with a given URL
157 | *
158 | * The delegate will be informed when the image is finish downloaded or an error has happen.
159 | *
160 | * @see SDWebImageDownloaderDelegate
161 | *
162 | * @param url The URL to the image to download
163 | * @param options The options to be used for this download
164 | * @param progressBlock A block called repeatedly while the image is downloading
165 | * @param completedBlock A block called once the download is completed.
166 | * If the download succeeded, the image parameter is set, in case of error,
167 | * error parameter is set with the error. The last parameter is always YES
168 | * if SDWebImageDownloaderProgressiveDownload isn't use. With the
169 | * SDWebImageDownloaderProgressiveDownload option, this block is called
170 | * repeatedly with the partial image object and the finished argument set to NO
171 | * before to be called a last time with the full image and finished argument
172 | * set to YES. In case of error, the finished argument is always YES.
173 | *
174 | * @return A cancellable SDWebImageOperation
175 | */
176 | - (id )downloadImageWithURL:(NSURL *)url
177 | options:(SDWebImageDownloaderOptions)options
178 | progress:(SDWebImageDownloaderProgressBlock)progressBlock
179 | completed:(SDWebImageDownloaderCompletedBlock)completedBlock;
180 |
181 | /**
182 | * Sets the download queue suspension state
183 | */
184 | - (void)setSuspended:(BOOL)suspended;
185 |
186 | @end
187 |
--------------------------------------------------------------------------------
/Classes/CycleAnimatorViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // CycleAnimatorViewController.m
3 | // CycleView_OC
4 | //
5 | // Created by SarielTang on 15/10/17.
6 | // Copyright © 2015年 SarielTang. All rights reserved.
7 | //
8 |
9 | #import "CycleAnimatorViewController.h"
10 | #import "NSTimer+SRTimer.h"
11 |
12 | static const NSArray *___SRTransitionAnimateType;
13 |
14 | // 创建初始化函数。等于用宏创建一个getter函数
15 |
16 | #define SRTransitionAnimateTypeGet (___SRTransitionAnimateType == nil ? ___SRTransitionAnimateType = [[NSArray alloc] initWithObjects:\
17 | @"fade",\
18 | @"movein",\
19 | @"push",\
20 | @"reveal",\
21 | @"cube",\
22 | @"oglFlip",\
23 | @"suckEffect",\
24 | @"rippleEffect",\
25 | @"pageCurl",\
26 | @"pageUnCurl",\
27 | @"cameralIrisHollowOpen",\
28 | @"cameraIrisHollowClose",nil] : ___SRTransitionAnimateType)
29 |
30 | // 枚举 to 字符串
31 |
32 | #define SRTransitionAnimateTypeString(type) ([SRTransitionAnimateTypeGet objectAtIndex:type])
33 |
34 | // 字符串 to 枚举
35 |
36 | #define SRTransitionAnimateTypeEnum(string) ([SRTransitionAnimateTypeGet indexOfObject:string])
37 |
38 | @interface CycleAnimatorViewController ()
39 |
40 | @property (nonatomic,assign)int currentIndex;
41 | @property (nonatomic,strong)NSTimer *animatorTimer;
42 | // pageController
43 | @property (nonatomic, strong) UIPageControl *pageControl;
44 |
45 | @end
46 |
47 | @implementation CycleAnimatorViewController
48 |
49 | - (void)loadView {
50 |
51 | self.view = [[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];
52 | // [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[imageView]-0-|" options:0 metrics:nil views:@{@"imageView": self.animatorImageView}]];
53 | // [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[imageView]-0-|" options:0 metrics:nil views:@{@"imageView": self.animatorImageView}]];
54 |
55 | //创建pageControl
56 | _pageControl = [[UIPageControl alloc] init];
57 | [self.view addSubview:self.pageControl];
58 |
59 | //设置初始化时间间隔
60 | _cycleTimeInterval = 4;
61 | _animationType = SRTransitionAnimateTypeCube;
62 | _isLimitGestureWhenAnimating = NO;
63 | }
64 |
65 | - (void)viewDidLoad {
66 | [super viewDidLoad];
67 |
68 | UISwipeGestureRecognizer *leftSwiperGesture = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(leftSwipe:)];
69 | leftSwiperGesture.direction = UISwipeGestureRecognizerDirectionLeft;
70 | [self.view addGestureRecognizer:leftSwiperGesture];
71 | // leftSwiperGesture.delegate = self;
72 |
73 | UISwipeGestureRecognizer *rightSwiperGesture = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(rightSwipe:)];
74 | rightSwiperGesture.direction = UISwipeGestureRecognizerDirectionRight;
75 | [self.view addGestureRecognizer:rightSwiperGesture];
76 | // rightSwiperGesture.delegate = self;
77 | if (self.animatorImageList.count != 1) {
78 | [self timeStart];
79 | }
80 | }
81 |
82 | - (void)viewWillAppear:(BOOL)animated {
83 | [super viewWillAppear:animated];
84 | NSAssert(_animatorImageList,@"缺少animatorImageList");
85 |
86 | [self.animatorTimer resumeTimerAfterTimeInterval:self.cycleTimeInterval];
87 |
88 | self.pageControl.numberOfPages = self.animatorImageList.count;
89 | self.pageControl.center = CGPointMake(self.view.frame.size.width * 0.5, self.view.frame.size.height * 0.9);
90 | [self.view bringSubviewToFront:self.pageControl];
91 |
92 | [self.animatorImageView setImage:self.animatorImageList[self.currentIndex]];
93 | }
94 |
95 | - (void)viewWillDisappear:(BOOL)animated {
96 | [super viewWillDisappear:animated];
97 | [self.animatorTimer pauseTimer];
98 | }
99 |
100 | //- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
101 | // [self.animatorTimer pauseTimer];
102 | // return YES;
103 | //}
104 |
105 | //- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
106 | // [self.animatorTimer pauseTimer];
107 | //}
108 |
109 | //- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
110 | // [self.animatorTimer resumeTimerAfterTimeInterval:(self.cycleTimeInterval * 0.5)];
111 | //}
112 |
113 | //- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
114 | // if ([touch.view isKindOfClass:[UIImageView class]]) {
115 | // return NO;
116 | // }
117 | // // 若为UITableViewCellContentView(即点击了tableViewCell),则不截获Touch事件
118 | // if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {
119 | // return NO;
120 | // }
121 | // return YES;
122 | //}
123 |
124 | - (void)leftSwipe:(UISwipeGestureRecognizer *)gesture {
125 | if (gesture.state == UIGestureRecognizerStateBegan) {
126 | [self.animatorTimer pauseTimer];
127 | }
128 | [self transitionAnimation:YES];
129 | if (gesture.state == UIGestureRecognizerStateEnded) {
130 | [self.animatorTimer resumeTimerAfterTimeInterval:(self.cycleTimeInterval)];
131 | }
132 | }
133 |
134 | - (void)rightSwipe:(UISwipeGestureRecognizer *)gesture {
135 | if (gesture.state == UIGestureRecognizerStateBegan) {
136 | [self.animatorTimer pauseTimer];
137 | }
138 | [self transitionAnimation:NO];
139 | if (gesture.state == UIGestureRecognizerStateEnded) {
140 | [self.animatorTimer resumeTimerAfterTimeInterval:(self.cycleTimeInterval)];
141 | }
142 | }
143 |
144 | - (void)timeStart {
145 | // 1. 创建定时器
146 | self.animatorTimer = [NSTimer timerWithTimeInterval:self.cycleTimeInterval target:self selector:@selector(nextImage) userInfo:nil repeats:YES];
147 |
148 | // 2. 添加定时器
149 | [[NSRunLoop currentRunLoop] addTimer:self.animatorTimer forMode:NSRunLoopCommonModes];
150 | }
151 |
152 | - (void)nextImage {
153 | [self transitionAnimation:YES];
154 | }
155 |
156 | static bool isAnimating;
157 | //转场动画
158 | - (void)transitionAnimation:(BOOL)isNext {
159 | if (!isAnimating) {
160 | // NSLog(@"isAnimating----%d",isAnimating);
161 | CATransition *transition = [[CATransition alloc]init];
162 | transition.type = SRTransitionAnimateTypeString(_animationType);
163 |
164 | if (self.isLimitGestureWhenAnimating) {
165 | transition.delegate = self;
166 | }
167 |
168 | //设置子类型
169 | if (isNext) {
170 | transition.subtype=kCATransitionFromRight;
171 | }else{
172 | transition.subtype=kCATransitionFromLeft;
173 | }
174 | //设置动画时常
175 | transition.duration=1.0;
176 |
177 | //3.设置转场后的新视图添加转场动画
178 | [self.animatorImageView setImage:[self getImage:isNext]];
179 | [self.animatorImageView.layer addAnimation:transition forKey:@"SRTransitionAnimation"];
180 |
181 | }
182 | }
183 |
184 | - (void)animationDidStart:(CAAnimation *)anim {
185 | isAnimating = YES;
186 | }
187 |
188 | - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
189 | isAnimating = NO;
190 | }
191 |
192 | //取得当前图片
193 | - (UIImage *)getImage:(BOOL)isNext {
194 | if (isNext) {
195 | self.currentIndex = (self.currentIndex+1)%self.animatorImageList.count;
196 | }else{
197 | self.currentIndex = (self.currentIndex-1+self.animatorImageList.count)%((int)self.animatorImageList.count);
198 | }
199 | self.pageControl.currentPage = self.currentIndex;
200 | return self.animatorImageList[self.currentIndex];
201 | }
202 |
203 | - (UIImageView *)animatorImageView {
204 | if (_animatorImageView == nil) {
205 | _animatorImageView = [[UIImageView alloc]initWithFrame:self.view.bounds];
206 | [self.view addSubview:self.animatorImageView];
207 | _animatorImageView.userInteractionEnabled = YES;
208 | UIGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(imageViewDidClicked)];
209 | [_animatorImageView addGestureRecognizer:singleTap];
210 | // [_animatorImageView addTarget:self action:@selector(imageViewDidClicked) forControlEvents:UIControlEventTouchUpInside];
211 | }
212 | return _animatorImageView;
213 | }
214 |
215 | - (void)imageViewDidClicked {
216 | // NSLog(@"---------imageViewDidClicked");
217 | if (self.delegate) {
218 | if ([self.delegate respondsToSelector:@selector(pictureCycleCellDidSelected:)]) {
219 | [self.delegate pictureCycleCellDidSelected:self.currentIndex];
220 | }
221 | }
222 | }
223 |
224 | - (NSArray *)animatorImageList {
225 | if (_animatorImageList == nil) {
226 | _animatorImageList = [NSArray array];
227 | }
228 | return _animatorImageList;
229 | }
230 | @end
231 |
--------------------------------------------------------------------------------
/SDWebImage/SDImageCache.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import
10 | #import "SDWebImageCompat.h"
11 |
12 | typedef NS_ENUM(NSInteger, SDImageCacheType) {
13 | /**
14 | * The image wasn't available the SDWebImage caches, but was downloaded from the web.
15 | */
16 | SDImageCacheTypeNone,
17 | /**
18 | * The image was obtained from the disk cache.
19 | */
20 | SDImageCacheTypeDisk,
21 | /**
22 | * The image was obtained from the memory cache.
23 | */
24 | SDImageCacheTypeMemory
25 | };
26 |
27 | typedef void(^SDWebImageQueryCompletedBlock)(UIImage *image, SDImageCacheType cacheType);
28 |
29 | typedef void(^SDWebImageCheckCacheCompletionBlock)(BOOL isInCache);
30 |
31 | typedef void(^SDWebImageCalculateSizeBlock)(NSUInteger fileCount, NSUInteger totalSize);
32 |
33 | /**
34 | * SDImageCache maintains a memory cache and an optional disk cache. Disk cache write operations are performed
35 | * asynchronous so it doesn’t add unnecessary latency to the UI.
36 | */
37 | @interface SDImageCache : NSObject
38 |
39 | /**
40 | * Decompressing images that are downloaded and cached can improve peformance 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 | * The maximum "total cost" of the in-memory image cache. The cost function is the number of pixels held in memory.
47 | */
48 | @property (assign, nonatomic) NSUInteger maxMemoryCost;
49 |
50 | /**
51 | * The maximum number of objects the cache should hold.
52 | */
53 | @property (assign, nonatomic) NSUInteger maxMemoryCountLimit;
54 |
55 | /**
56 | * The maximum length of time to keep an image in the cache, in seconds
57 | */
58 | @property (assign, nonatomic) NSInteger maxCacheAge;
59 |
60 | /**
61 | * The maximum size of the cache, in bytes.
62 | */
63 | @property (assign, nonatomic) NSUInteger maxCacheSize;
64 |
65 | /**
66 | * Returns global shared cache instance
67 | *
68 | * @return SDImageCache global instance
69 | */
70 | + (SDImageCache *)sharedImageCache;
71 |
72 | /**
73 | * Init a new cache store with a specific namespace
74 | *
75 | * @param ns The namespace to use for this cache store
76 | */
77 | - (id)initWithNamespace:(NSString *)ns;
78 |
79 | /**
80 | * Init a new cache store with a specific namespace and directory
81 | *
82 | * @param ns The namespace to use for this cache store
83 | * @param directory Directory to cache disk images in
84 | */
85 | - (id)initWithNamespace:(NSString *)ns diskCacheDirectory:(NSString *)directory;
86 |
87 | -(NSString *)makeDiskCachePath:(NSString*)fullNamespace;
88 |
89 | /**
90 | * Add a read-only cache path to search for images pre-cached by SDImageCache
91 | * Useful if you want to bundle pre-loaded images with your app
92 | *
93 | * @param path The path to use for this read-only cache path
94 | */
95 | - (void)addReadOnlyCachePath:(NSString *)path;
96 |
97 | /**
98 | * Store an image into memory and disk cache at the given key.
99 | *
100 | * @param image The image to store
101 | * @param key The unique image cache key, usually it's image absolute URL
102 | */
103 | - (void)storeImage:(UIImage *)image forKey:(NSString *)key;
104 |
105 | /**
106 | * Store an image into memory and optionally disk cache at the given key.
107 | *
108 | * @param image The image to store
109 | * @param key The unique image cache key, usually it's image absolute URL
110 | * @param toDisk Store the image to disk cache if YES
111 | */
112 | - (void)storeImage:(UIImage *)image forKey:(NSString *)key toDisk:(BOOL)toDisk;
113 |
114 | /**
115 | * Store an image into memory and optionally disk cache at the given key.
116 | *
117 | * @param image The image to store
118 | * @param recalculate BOOL indicates if imageData can be used or a new data should be constructed from the UIImage
119 | * @param imageData The image data as returned by the server, this representation will be used for disk storage
120 | * instead of converting the given image object into a storable/compressed image format in order
121 | * to save quality and CPU
122 | * @param key The unique image cache key, usually it's image absolute URL
123 | * @param toDisk Store the image to disk cache if YES
124 | */
125 | - (void)storeImage:(UIImage *)image recalculateFromImage:(BOOL)recalculate imageData:(NSData *)imageData forKey:(NSString *)key toDisk:(BOOL)toDisk;
126 |
127 | /**
128 | * Query the disk cache asynchronously.
129 | *
130 | * @param key The unique key used to store the wanted image
131 | */
132 | - (NSOperation *)queryDiskCacheForKey:(NSString *)key done:(SDWebImageQueryCompletedBlock)doneBlock;
133 |
134 | /**
135 | * Query the memory cache synchronously.
136 | *
137 | * @param key The unique key used to store the wanted image
138 | */
139 | - (UIImage *)imageFromMemoryCacheForKey:(NSString *)key;
140 |
141 | /**
142 | * Query the disk cache synchronously after checking the memory cache.
143 | *
144 | * @param key The unique key used to store the wanted image
145 | */
146 | - (UIImage *)imageFromDiskCacheForKey:(NSString *)key;
147 |
148 | /**
149 | * Remove the image from memory and disk cache synchronously
150 | *
151 | * @param key The unique image cache key
152 | */
153 | - (void)removeImageForKey:(NSString *)key;
154 |
155 |
156 | /**
157 | * Remove the image from memory and disk cache asynchronously
158 | *
159 | * @param key The unique image cache key
160 | * @param completion An block that should be executed after the image has been removed (optional)
161 | */
162 | - (void)removeImageForKey:(NSString *)key withCompletion:(SDWebImageNoParamsBlock)completion;
163 |
164 | /**
165 | * Remove the image from memory and optionally disk cache asynchronously
166 | *
167 | * @param key The unique image cache key
168 | * @param fromDisk Also remove cache entry from disk if YES
169 | */
170 | - (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk;
171 |
172 | /**
173 | * Remove the image from memory and optionally disk cache asynchronously
174 | *
175 | * @param key The unique image cache key
176 | * @param fromDisk Also remove cache entry from disk if YES
177 | * @param completion An block that should be executed after the image has been removed (optional)
178 | */
179 | - (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk withCompletion:(SDWebImageNoParamsBlock)completion;
180 |
181 | /**
182 | * Clear all memory cached images
183 | */
184 | - (void)clearMemory;
185 |
186 | /**
187 | * Clear all disk cached images. Non-blocking method - returns immediately.
188 | * @param completion An block that should be executed after cache expiration completes (optional)
189 | */
190 | - (void)clearDiskOnCompletion:(SDWebImageNoParamsBlock)completion;
191 |
192 | /**
193 | * Clear all disk cached images
194 | * @see clearDiskOnCompletion:
195 | */
196 | - (void)clearDisk;
197 |
198 | /**
199 | * Remove all expired cached image from disk. Non-blocking method - returns immediately.
200 | * @param completionBlock An block that should be executed after cache expiration completes (optional)
201 | */
202 | - (void)cleanDiskWithCompletionBlock:(SDWebImageNoParamsBlock)completionBlock;
203 |
204 | /**
205 | * Remove all expired cached image from disk
206 | * @see cleanDiskWithCompletionBlock:
207 | */
208 | - (void)cleanDisk;
209 |
210 | /**
211 | * Get the size used by the disk cache
212 | */
213 | - (NSUInteger)getSize;
214 |
215 | /**
216 | * Get the number of images in the disk cache
217 | */
218 | - (NSUInteger)getDiskCount;
219 |
220 | /**
221 | * Asynchronously calculate the disk cache's size.
222 | */
223 | - (void)calculateSizeWithCompletionBlock:(SDWebImageCalculateSizeBlock)completionBlock;
224 |
225 | /**
226 | * Async check if image exists in disk cache already (does not load the image)
227 | *
228 | * @param key the key describing the url
229 | * @param completionBlock the block to be executed when the check is done.
230 | * @note the completion block will be always executed on the main queue
231 | */
232 | - (void)diskImageExistsWithKey:(NSString *)key completion:(SDWebImageCheckCacheCompletionBlock)completionBlock;
233 |
234 | /**
235 | * Check if image exists in disk cache already (does not load the image)
236 | *
237 | * @param key the key describing the url
238 | *
239 | * @return YES if an image exists for the given key
240 | */
241 | - (BOOL)diskImageExistsWithKey:(NSString *)key;
242 |
243 | /**
244 | * Get the cache path for a certain key (needs the cache path root folder)
245 | *
246 | * @param key the key (can be obtained from url using cacheKeyForURL)
247 | * @param path the cach path root folder
248 | *
249 | * @return the cache path
250 | */
251 | - (NSString *)cachePathForKey:(NSString *)key inPath:(NSString *)path;
252 |
253 | /**
254 | * Get the default cache path for a certain key
255 | *
256 | * @param key the key (can be obtained from url using cacheKeyForURL)
257 | *
258 | * @return the default cache path
259 | */
260 | - (NSString *)defaultCachePathForKey:(NSString *)key;
261 |
262 | @end
263 |
--------------------------------------------------------------------------------
/SDWebImage/UIImageView+WebCache.m:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import "UIImageView+WebCache.h"
10 | #import "objc/runtime.h"
11 | #import "UIView+WebCacheOperation.h"
12 |
13 | static char imageURLKey;
14 |
15 | @implementation UIImageView (WebCache)
16 |
17 | - (void)sd_setImageWithURL:(NSURL *)url {
18 | [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil];
19 | }
20 |
21 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
22 | [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil];
23 | }
24 |
25 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
26 | [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil];
27 | }
28 |
29 | - (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock {
30 | [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:completedBlock];
31 | }
32 |
33 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock {
34 | [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:completedBlock];
35 | }
36 |
37 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
38 | [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:completedBlock];
39 | }
40 |
41 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock {
42 | [self sd_cancelCurrentImageLoad];
43 | objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
44 |
45 | if (!(options & SDWebImageDelayPlaceholder)) {
46 | dispatch_main_async_safe(^{
47 | self.image = placeholder;
48 | });
49 | }
50 |
51 | if (url) {
52 | __weak __typeof(self)wself = self;
53 | id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
54 | if (!wself) return;
55 | dispatch_main_sync_safe(^{
56 | if (!wself) return;
57 | if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock)
58 | {
59 | completedBlock(image, error, cacheType, url);
60 | return;
61 | }
62 | else if (image) {
63 | wself.image = image;
64 | [wself setNeedsLayout];
65 | } else {
66 | if ((options & SDWebImageDelayPlaceholder)) {
67 | wself.image = placeholder;
68 | [wself setNeedsLayout];
69 | }
70 | }
71 | if (completedBlock && finished) {
72 | completedBlock(image, error, cacheType, url);
73 | }
74 | });
75 | }];
76 | [self sd_setImageLoadOperation:operation forKey:@"UIImageViewImageLoad"];
77 | } else {
78 | dispatch_main_async_safe(^{
79 | NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
80 | if (completedBlock) {
81 | completedBlock(nil, error, SDImageCacheTypeNone, url);
82 | }
83 | });
84 | }
85 | }
86 |
87 | - (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url andPlaceholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock {
88 | NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:url];
89 | UIImage *lastPreviousCachedImage = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:key];
90 |
91 | [self sd_setImageWithURL:url placeholderImage:lastPreviousCachedImage ?: placeholder options:options progress:progressBlock completed:completedBlock];
92 | }
93 |
94 | - (NSURL *)sd_imageURL {
95 | return objc_getAssociatedObject(self, &imageURLKey);
96 | }
97 |
98 | - (void)sd_setAnimationImagesWithURLs:(NSArray *)arrayOfURLs {
99 | [self sd_cancelCurrentAnimationImagesLoad];
100 | __weak __typeof(self)wself = self;
101 |
102 | NSMutableArray *operationsArray = [[NSMutableArray alloc] init];
103 |
104 | for (NSURL *logoImageURL in arrayOfURLs) {
105 | id operation = [SDWebImageManager.sharedManager downloadImageWithURL:logoImageURL options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
106 | if (!wself) return;
107 | dispatch_main_sync_safe(^{
108 | __strong UIImageView *sself = wself;
109 | [sself stopAnimating];
110 | if (sself && image) {
111 | NSMutableArray *currentImages = [[sself animationImages] mutableCopy];
112 | if (!currentImages) {
113 | currentImages = [[NSMutableArray alloc] init];
114 | }
115 | [currentImages addObject:image];
116 |
117 | sself.animationImages = currentImages;
118 | [sself setNeedsLayout];
119 | }
120 | [sself startAnimating];
121 | });
122 | }];
123 | [operationsArray addObject:operation];
124 | }
125 |
126 | [self sd_setImageLoadOperation:[NSArray arrayWithArray:operationsArray] forKey:@"UIImageViewAnimationImages"];
127 | }
128 |
129 | - (void)sd_cancelCurrentImageLoad {
130 | [self sd_cancelImageLoadOperationWithKey:@"UIImageViewImageLoad"];
131 | }
132 |
133 | - (void)sd_cancelCurrentAnimationImagesLoad {
134 | [self sd_cancelImageLoadOperationWithKey:@"UIImageViewAnimationImages"];
135 | }
136 |
137 | @end
138 |
139 |
140 | @implementation UIImageView (WebCacheDeprecated)
141 |
142 | - (NSURL *)imageURL {
143 | return [self sd_imageURL];
144 | }
145 |
146 | - (void)setImageWithURL:(NSURL *)url {
147 | [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:nil];
148 | }
149 |
150 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
151 | [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil];
152 | }
153 |
154 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
155 | [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:nil];
156 | }
157 |
158 | - (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock {
159 | [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
160 | if (completedBlock) {
161 | completedBlock(image, error, cacheType);
162 | }
163 | }];
164 | }
165 |
166 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock {
167 | [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
168 | if (completedBlock) {
169 | completedBlock(image, error, cacheType);
170 | }
171 | }];
172 | }
173 |
174 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
175 | [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
176 | if (completedBlock) {
177 | completedBlock(image, error, cacheType);
178 | }
179 | }];
180 | }
181 |
182 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock {
183 | [self sd_setImageWithURL:url placeholderImage:placeholder options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
184 | if (completedBlock) {
185 | completedBlock(image, error, cacheType);
186 | }
187 | }];
188 | }
189 |
190 | - (void)cancelCurrentArrayLoad {
191 | [self sd_cancelCurrentAnimationImagesLoad];
192 | }
193 |
194 | - (void)cancelCurrentImageLoad {
195 | [self sd_cancelCurrentImageLoad];
196 | }
197 |
198 | - (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs {
199 | [self sd_setAnimationImagesWithURLs:arrayOfURLs];
200 | }
201 |
202 | @end
203 |
--------------------------------------------------------------------------------
/SDWebImage/UIImageView+WebCache.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import "SDWebImageCompat.h"
10 | #import "SDWebImageManager.h"
11 |
12 | /**
13 | * Integrates SDWebImage async downloading and caching of remote images with UIImageView.
14 | *
15 | * Usage with a UITableViewCell sub-class:
16 | *
17 | * @code
18 |
19 | #import
20 |
21 | ...
22 |
23 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
24 | {
25 | static NSString *MyIdentifier = @"MyIdentifier";
26 |
27 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
28 |
29 | if (cell == nil) {
30 | cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier]
31 | autorelease];
32 | }
33 |
34 | // Here we use the provided sd_setImageWithURL: method to load the web image
35 | // Ensure you use a placeholder image otherwise cells will be initialized with no image
36 | [cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://example.com/image.jpg"]
37 | placeholderImage:[UIImage imageNamed:@"placeholder"]];
38 |
39 | cell.textLabel.text = @"My Text";
40 | return cell;
41 | }
42 |
43 | * @endcode
44 | */
45 | @interface UIImageView (WebCache)
46 |
47 | /**
48 | * Get the current image URL.
49 | *
50 | * Note that because of the limitations of categories this property can get out of sync
51 | * if you use sd_setImage: directly.
52 | */
53 | - (NSURL *)sd_imageURL;
54 |
55 | /**
56 | * Set the imageView `image` with an `url`.
57 | *
58 | * The download is asynchronous and cached.
59 | *
60 | * @param url The url for the image.
61 | */
62 | - (void)sd_setImageWithURL:(NSURL *)url;
63 |
64 | /**
65 | * Set the imageView `image` with an `url` and a placeholder.
66 | *
67 | * The download is asynchronous and cached.
68 | *
69 | * @param url The url for the image.
70 | * @param placeholder The image to be set initially, until the image request finishes.
71 | * @see sd_setImageWithURL:placeholderImage:options:
72 | */
73 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder;
74 |
75 | /**
76 | * Set the imageView `image` with an `url`, placeholder and custom options.
77 | *
78 | * The download is asynchronous and cached.
79 | *
80 | * @param url The url for the image.
81 | * @param placeholder The image to be set initially, until the image request finishes.
82 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
83 | */
84 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
85 |
86 | /**
87 | * Set the imageView `image` with an `url`.
88 | *
89 | * The download is asynchronous and cached.
90 | *
91 | * @param url The url for the image.
92 | * @param completedBlock A block called when operation has been completed. This block has no return value
93 | * and takes the requested UIImage as first parameter. In case of error the image parameter
94 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
95 | * indicating if the image was retrived from the local cache or from the network.
96 | * The fourth parameter is the original image url.
97 | */
98 | - (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock;
99 |
100 | /**
101 | * Set the imageView `image` with an `url`, placeholder.
102 | *
103 | * The download is asynchronous and cached.
104 | *
105 | * @param url The url for the image.
106 | * @param placeholder The image to be set initially, until the image request finishes.
107 | * @param completedBlock A block called when operation has been completed. This block has no return value
108 | * and takes the requested UIImage as first parameter. In case of error the image parameter
109 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
110 | * indicating if the image was retrived from the local cache or from the network.
111 | * The fourth parameter is the original image url.
112 | */
113 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock;
114 |
115 | /**
116 | * Set the imageView `image` with an `url`, placeholder and custom options.
117 | *
118 | * The download is asynchronous and cached.
119 | *
120 | * @param url The url for the image.
121 | * @param placeholder The image to be set initially, until the image request finishes.
122 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
123 | * @param completedBlock A block called when operation has been completed. This block has no return value
124 | * and takes the requested UIImage as first parameter. In case of error the image parameter
125 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
126 | * indicating if the image was retrived from the local cache or from the network.
127 | * The fourth parameter is the original image url.
128 | */
129 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
130 |
131 | /**
132 | * Set the imageView `image` with an `url`, placeholder and custom options.
133 | *
134 | * The download is asynchronous and cached.
135 | *
136 | * @param url The url for the image.
137 | * @param placeholder The image to be set initially, until the image request finishes.
138 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
139 | * @param progressBlock A block called while image is downloading
140 | * @param completedBlock A block called when operation has been completed. This block has no return value
141 | * and takes the requested UIImage as first parameter. In case of error the image parameter
142 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
143 | * indicating if the image was retrived from the local cache or from the network.
144 | * The fourth parameter is the original image url.
145 | */
146 | - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock;
147 |
148 | /**
149 | * Set the imageView `image` with an `url` and a optionaly placeholder image.
150 | *
151 | * The download is asynchronous and cached.
152 | *
153 | * @param url The url for the image.
154 | * @param placeholder The image to be set initially, until the image request finishes.
155 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
156 | * @param progressBlock A block called while image is downloading
157 | * @param completedBlock A block called when operation has been completed. This block has no return value
158 | * and takes the requested UIImage as first parameter. In case of error the image parameter
159 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
160 | * indicating if the image was retrived from the local cache or from the network.
161 | * The fourth parameter is the original image url.
162 | */
163 | - (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url andPlaceholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock;
164 |
165 | /**
166 | * Download an array of images and starts them in an animation loop
167 | *
168 | * @param arrayOfURLs An array of NSURL
169 | */
170 | - (void)sd_setAnimationImagesWithURLs:(NSArray *)arrayOfURLs;
171 |
172 | /**
173 | * Cancel the current download
174 | */
175 | - (void)sd_cancelCurrentImageLoad;
176 |
177 | - (void)sd_cancelCurrentAnimationImagesLoad;
178 |
179 | @end
180 |
181 |
182 | @interface UIImageView (WebCacheDeprecated)
183 |
184 | - (NSURL *)imageURL __deprecated_msg("Use `sd_imageURL`");
185 |
186 | - (void)setImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:`");
187 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:`");
188 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options`");
189 |
190 | - (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:completed:`");
191 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:completed:`");
192 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:completed:`");
193 | - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:placeholderImage:options:progress:completed:`");
194 |
195 | - (void)setAnimationImagesWithURLs:(NSArray *)arrayOfURLs __deprecated_msg("Use `sd_setAnimationImagesWithURLs:`");
196 |
197 | - (void)cancelCurrentArrayLoad __deprecated_msg("Use `sd_cancelCurrentAnimationImagesLoad`");
198 |
199 | - (void)cancelCurrentImageLoad __deprecated_msg("Use `sd_cancelCurrentImageLoad`");
200 |
201 | @end
202 |
--------------------------------------------------------------------------------
/SDWebImage/SDWebImageDownloader.m:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import "SDWebImageDownloader.h"
10 | #import "SDWebImageDownloaderOperation.h"
11 | #import
12 |
13 | static NSString *const kProgressCallbackKey = @"progress";
14 | static NSString *const kCompletedCallbackKey = @"completed";
15 |
16 | @interface SDWebImageDownloader ()
17 |
18 | @property (strong, nonatomic) NSOperationQueue *downloadQueue;
19 | @property (weak, nonatomic) NSOperation *lastAddedOperation;
20 | @property (assign, nonatomic) Class operationClass;
21 | @property (strong, nonatomic) NSMutableDictionary *URLCallbacks;
22 | @property (strong, nonatomic) NSMutableDictionary *HTTPHeaders;
23 | // This queue is used to serialize the handling of the network responses of all the download operation in a single queue
24 | @property (SDDispatchQueueSetterSementics, nonatomic) dispatch_queue_t barrierQueue;
25 |
26 | @end
27 |
28 | @implementation SDWebImageDownloader
29 |
30 | + (void)initialize {
31 | // Bind SDNetworkActivityIndicator if available (download it here: http://github.com/rs/SDNetworkActivityIndicator )
32 | // To use it, just add #import "SDNetworkActivityIndicator.h" in addition to the SDWebImage import
33 | if (NSClassFromString(@"SDNetworkActivityIndicator")) {
34 |
35 | #pragma clang diagnostic push
36 | #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
37 | id activityIndicator = [NSClassFromString(@"SDNetworkActivityIndicator") performSelector:NSSelectorFromString(@"sharedActivityIndicator")];
38 | #pragma clang diagnostic pop
39 |
40 | // Remove observer in case it was previously added.
41 | [[NSNotificationCenter defaultCenter] removeObserver:activityIndicator name:SDWebImageDownloadStartNotification object:nil];
42 | [[NSNotificationCenter defaultCenter] removeObserver:activityIndicator name:SDWebImageDownloadStopNotification object:nil];
43 |
44 | [[NSNotificationCenter defaultCenter] addObserver:activityIndicator
45 | selector:NSSelectorFromString(@"startActivity")
46 | name:SDWebImageDownloadStartNotification object:nil];
47 | [[NSNotificationCenter defaultCenter] addObserver:activityIndicator
48 | selector:NSSelectorFromString(@"stopActivity")
49 | name:SDWebImageDownloadStopNotification object:nil];
50 | }
51 | }
52 |
53 | + (SDWebImageDownloader *)sharedDownloader {
54 | static dispatch_once_t once;
55 | static id instance;
56 | dispatch_once(&once, ^{
57 | instance = [self new];
58 | });
59 | return instance;
60 | }
61 |
62 | - (id)init {
63 | if ((self = [super init])) {
64 | _operationClass = [SDWebImageDownloaderOperation class];
65 | _shouldDecompressImages = YES;
66 | _executionOrder = SDWebImageDownloaderFIFOExecutionOrder;
67 | _downloadQueue = [NSOperationQueue new];
68 | _downloadQueue.maxConcurrentOperationCount = 6;
69 | _URLCallbacks = [NSMutableDictionary new];
70 | #ifdef SD_WEBP
71 | _HTTPHeaders = [@{@"Accept": @"image/webp,image/*;q=0.8"} mutableCopy];
72 | #else
73 | _HTTPHeaders = [@{@"Accept": @"image/*;q=0.8"} mutableCopy];
74 | #endif
75 | _barrierQueue = dispatch_queue_create("com.hackemist.SDWebImageDownloaderBarrierQueue", DISPATCH_QUEUE_CONCURRENT);
76 | _downloadTimeout = 15.0;
77 | }
78 | return self;
79 | }
80 |
81 | - (void)dealloc {
82 | [self.downloadQueue cancelAllOperations];
83 | SDDispatchQueueRelease(_barrierQueue);
84 | }
85 |
86 | - (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field {
87 | if (value) {
88 | self.HTTPHeaders[field] = value;
89 | }
90 | else {
91 | [self.HTTPHeaders removeObjectForKey:field];
92 | }
93 | }
94 |
95 | - (NSString *)valueForHTTPHeaderField:(NSString *)field {
96 | return self.HTTPHeaders[field];
97 | }
98 |
99 | - (void)setMaxConcurrentDownloads:(NSInteger)maxConcurrentDownloads {
100 | _downloadQueue.maxConcurrentOperationCount = maxConcurrentDownloads;
101 | }
102 |
103 | - (NSUInteger)currentDownloadCount {
104 | return _downloadQueue.operationCount;
105 | }
106 |
107 | - (NSInteger)maxConcurrentDownloads {
108 | return _downloadQueue.maxConcurrentOperationCount;
109 | }
110 |
111 | - (void)setOperationClass:(Class)operationClass {
112 | _operationClass = operationClass ?: [SDWebImageDownloaderOperation class];
113 | }
114 |
115 | - (id )downloadImageWithURL:(NSURL *)url options:(SDWebImageDownloaderOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageDownloaderCompletedBlock)completedBlock {
116 | __block SDWebImageDownloaderOperation *operation;
117 | __weak __typeof(self)wself = self;
118 |
119 | [self addProgressCallback:progressBlock andCompletedBlock:completedBlock forURL:url createCallback:^{
120 | NSTimeInterval timeoutInterval = wself.downloadTimeout;
121 | if (timeoutInterval == 0.0) {
122 | timeoutInterval = 15.0;
123 | }
124 |
125 | // In order to prevent from potential duplicate caching (NSURLCache + SDImageCache) we disable the cache for image requests if told otherwise
126 | NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:(options & SDWebImageDownloaderUseNSURLCache ? NSURLRequestUseProtocolCachePolicy : NSURLRequestReloadIgnoringLocalCacheData) timeoutInterval:timeoutInterval];
127 | request.HTTPShouldHandleCookies = (options & SDWebImageDownloaderHandleCookies);
128 | request.HTTPShouldUsePipelining = YES;
129 | if (wself.headersFilter) {
130 | request.allHTTPHeaderFields = wself.headersFilter(url, [wself.HTTPHeaders copy]);
131 | }
132 | else {
133 | request.allHTTPHeaderFields = wself.HTTPHeaders;
134 | }
135 | operation = [[wself.operationClass alloc] initWithRequest:request
136 | options:options
137 | progress:^(NSInteger receivedSize, NSInteger expectedSize) {
138 | SDWebImageDownloader *sself = wself;
139 | if (!sself) return;
140 | __block NSArray *callbacksForURL;
141 | dispatch_sync(sself.barrierQueue, ^{
142 | callbacksForURL = [sself.URLCallbacks[url] copy];
143 | });
144 | for (NSDictionary *callbacks in callbacksForURL) {
145 | SDWebImageDownloaderProgressBlock callback = callbacks[kProgressCallbackKey];
146 | if (callback) callback(receivedSize, expectedSize);
147 | }
148 | }
149 | completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
150 | SDWebImageDownloader *sself = wself;
151 | if (!sself) return;
152 | __block NSArray *callbacksForURL;
153 | dispatch_barrier_sync(sself.barrierQueue, ^{
154 | callbacksForURL = [sself.URLCallbacks[url] copy];
155 | if (finished) {
156 | [sself.URLCallbacks removeObjectForKey:url];
157 | }
158 | });
159 | for (NSDictionary *callbacks in callbacksForURL) {
160 | SDWebImageDownloaderCompletedBlock callback = callbacks[kCompletedCallbackKey];
161 | if (callback) callback(image, data, error, finished);
162 | }
163 | }
164 | cancelled:^{
165 | SDWebImageDownloader *sself = wself;
166 | if (!sself) return;
167 | dispatch_barrier_async(sself.barrierQueue, ^{
168 | [sself.URLCallbacks removeObjectForKey:url];
169 | });
170 | }];
171 | operation.shouldDecompressImages = wself.shouldDecompressImages;
172 |
173 | if (wself.username && wself.password) {
174 | operation.credential = [NSURLCredential credentialWithUser:wself.username password:wself.password persistence:NSURLCredentialPersistenceForSession];
175 | }
176 |
177 | if (options & SDWebImageDownloaderHighPriority) {
178 | operation.queuePriority = NSOperationQueuePriorityHigh;
179 | } else if (options & SDWebImageDownloaderLowPriority) {
180 | operation.queuePriority = NSOperationQueuePriorityLow;
181 | }
182 |
183 | [wself.downloadQueue addOperation:operation];
184 | if (wself.executionOrder == SDWebImageDownloaderLIFOExecutionOrder) {
185 | // Emulate LIFO execution order by systematically adding new operations as last operation's dependency
186 | [wself.lastAddedOperation addDependency:operation];
187 | wself.lastAddedOperation = operation;
188 | }
189 | }];
190 |
191 | return operation;
192 | }
193 |
194 | - (void)addProgressCallback:(SDWebImageDownloaderProgressBlock)progressBlock andCompletedBlock:(SDWebImageDownloaderCompletedBlock)completedBlock forURL:(NSURL *)url createCallback:(SDWebImageNoParamsBlock)createCallback {
195 | // 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.
196 | if (url == nil) {
197 | if (completedBlock != nil) {
198 | completedBlock(nil, nil, nil, NO);
199 | }
200 | return;
201 | }
202 |
203 | dispatch_barrier_sync(self.barrierQueue, ^{
204 | BOOL first = NO;
205 | if (!self.URLCallbacks[url]) {
206 | self.URLCallbacks[url] = [NSMutableArray new];
207 | first = YES;
208 | }
209 |
210 | // Handle single download of simultaneous download request for the same URL
211 | NSMutableArray *callbacksForURL = self.URLCallbacks[url];
212 | NSMutableDictionary *callbacks = [NSMutableDictionary new];
213 | if (progressBlock) callbacks[kProgressCallbackKey] = [progressBlock copy];
214 | if (completedBlock) callbacks[kCompletedCallbackKey] = [completedBlock copy];
215 | [callbacksForURL addObject:callbacks];
216 | self.URLCallbacks[url] = callbacksForURL;
217 |
218 | if (first) {
219 | createCallback();
220 | }
221 | });
222 | }
223 |
224 | - (void)setSuspended:(BOOL)suspended {
225 | [self.downloadQueue setSuspended:suspended];
226 | }
227 |
228 | @end
229 |
--------------------------------------------------------------------------------
/Classes/PictureCycleViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // PictureCycleViewController.m
3 | // S01-图片轮播()
4 | //
5 | // Created by Jerry on 15/7/3.
6 | // Copyright (c) 2015年 Jerry. All rights reserved.
7 | //
8 |
9 | #import "PictureCycleViewController.h"
10 | #import "PictureCycleCell.h"
11 | #import "NSTimer+SRTimer.h"
12 | #import "UIImageView+WebCache.h"
13 | #import "UIImage+color.h"
14 |
15 | @interface PictureCycleViewController ()
16 |
17 | /// 当前图片索引
18 | @property (nonatomic, assign) NSInteger currentIndex;
19 |
20 | /// 循环时间
21 | @property (nonatomic, strong) NSTimer *cycleTimer;
22 |
23 | // 对于只有两个页面的timer
24 | @property (nonatomic,strong) NSTimer *cycleTimer2;
25 |
26 | /// 循环布局
27 | @property (nonatomic, strong) UICollectionViewFlowLayout *layout;
28 |
29 | // pageController
30 | @property (nonatomic, strong) UIPageControl *pageControl;
31 |
32 | @property (nonatomic,strong) NSArray *cycleList;
33 |
34 | @end
35 |
36 | @implementation PictureCycleViewController
37 |
38 | static NSString * const reuseIdentifier = @"PictureCycleCellID";
39 |
40 | //cell被选中的代理方法
41 | - (void)pictureCycleCellDidSelected:(NSInteger)itemTag {
42 | NSLog(@"选中第%zd张图片",itemTag);
43 | }
44 |
45 | #pragma mark - CollectionView 操作函数
46 | // 加载 view
47 | - (void)loadView {
48 |
49 | // 创建view
50 | self.view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
51 | // 创建 collection 设置frame和布局
52 | self.collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout: self.layout];
53 | self.collectionView.showsHorizontalScrollIndicator = NO;
54 | self.collectionView.showsVerticalScrollIndicator = NO; // 关闭垂直滑动
55 | self.collectionView.pagingEnabled = YES; // 开启分页功能
56 | self.collectionView.dataSource = self; // 设置数据源代理
57 | self.collectionView.delegate = self;
58 |
59 | //创建pageControl
60 | self.pageControl = [[UIPageControl alloc] init];
61 | [self.collectionView.superview addSubview:self.pageControl];
62 |
63 | //设置初始化时间间隔
64 | self.cycleTimeInterval = 2;
65 | }
66 |
67 | // view 加载完成
68 | - (void)viewDidLoad {
69 | [super viewDidLoad];
70 |
71 | // Register cell classes (注册cell)
72 | [self.collectionView registerClass:[PictureCycleCell class] forCellWithReuseIdentifier:reuseIdentifier];
73 | }
74 |
75 | // view 即将显示
76 | - (void)viewWillAppear:(BOOL)animated {
77 | [super viewWillAppear:animated];
78 |
79 | if (self.isNetImage) {
80 | _cycleList = self.cycleImageUrls;
81 | if (_cycleList == nil) {
82 | _cycleList = @[@"http://"];
83 | }
84 | self.pageControl.numberOfPages = self.cycleImageUrls.count;
85 | }else{
86 | _cycleList = self.cycleImageList;
87 | if (_cycleList == nil) {
88 | _cycleList = @[[UIImage imageWithColor:[UIColor blackColor]]];
89 | }
90 | self.pageControl.numberOfPages = self.cycleImageList.count;
91 | }
92 | self.pageControl.center = CGPointMake(self.collectionView.superview.frame.size.width * 0.5, self.collectionView.frame.size.height * 0.9);
93 |
94 | if(self.pageControl.numberOfPages == 2){
95 | if (self.cycleTimer2 == nil) {
96 | [self time2Start];
97 | }else {
98 | [self.cycleTimer2 resumeTimerAfterTimeInterval:self.cycleTimeInterval];
99 | }
100 | }else if(self.pageControl.numberOfPages > 2){
101 | if (self.cycleTimer == nil) {
102 | [self timeStart];
103 | }else {
104 | [self.cycleTimer resumeTimerAfterTimeInterval:self.cycleTimeInterval];
105 | }
106 | // 设置从第2个页开始显示
107 | NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:0];
108 |
109 | // 设置滑动位置
110 | [self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];
111 | }
112 | }
113 |
114 | - (void)viewWillDisappear:(BOOL)animated {
115 | [super viewWillDisappear:animated];
116 | if (self.cycleList.count>2) {
117 | [self.cycleTimer pauseTimer];
118 | }else if(self.cycleList.count == 2){
119 | [self.cycleTimer2 pauseTimer];
120 | }
121 | }
122 |
123 | - (void)setCycleImageUrls:(NSArray *)cycleImageUrls {
124 | _cycleImageUrls = cycleImageUrls;
125 |
126 | _cycleList = self.cycleImageUrls;
127 | self.pageControl.numberOfPages = self.cycleImageUrls.count;
128 |
129 | if(self.pageControl.numberOfPages == 2){
130 | if (self.cycleTimer2 == nil) {
131 | [self time2Start];
132 | }else {
133 | [self.cycleTimer2 resumeTimerAfterTimeInterval:self.cycleTimeInterval];
134 | }
135 | [self.collectionView reloadData];
136 | }else if(self.pageControl.numberOfPages > 2){
137 | if (self.cycleTimer == nil) {
138 | [self timeStart];
139 | }else {
140 | [self.cycleTimer resumeTimerAfterTimeInterval:self.cycleTimeInterval];
141 | }
142 | [self.collectionView reloadData];
143 | // 设置从第2个页开始显示
144 | NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:0];
145 |
146 | // 设置滑动位置
147 | [self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];
148 | }
149 | }
150 |
151 | // layout 设置
152 | - (void)viewDidLayoutSubviews {
153 | // 设置 item 尺寸
154 | self.layout.itemSize = self.view.bounds.size;
155 | }
156 |
157 | #pragma mark - UICollectionViewDataSource 数据源方法
158 | // 返回组数
159 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
160 |
161 | return self.cycleList.count;
162 | }
163 |
164 | /// 返回 ItemTag
165 | - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
166 |
167 | PictureCycleCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
168 | // self.cellIndex = indexPath.item;
169 | NSInteger index;
170 | if (self.cycleList.count < 3) {
171 | index = indexPath.item;
172 | // NSLog(@"%ld",indexPath.item);
173 | }else {
174 | index = (indexPath.item - 1 + self.cycleList.count + self.currentIndex ) % self.cycleList.count;
175 | }
176 | if (self.isNetImage) {
177 | [cell.imageView sd_setImageWithURL:[NSURL URLWithString:self.cycleImageUrls[index]] placeholderImage:self.placeholderImage];
178 | }else {
179 | cell.image = self.cycleImageList[index];
180 | }
181 | cell.delegate = self;
182 | cell.itemTag = index;
183 |
184 | return cell;
185 | }
186 |
187 | #pragma mark - UIScrollView滚动结束后的代理方法
188 | - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
189 |
190 | if (self.pageControl.numberOfPages < 3) {
191 | NSInteger offset = (NSInteger)(self.collectionView.contentOffset.x / self.collectionView.bounds.size.width);
192 | self.pageControl.currentPage = offset;
193 | }else {
194 | NSInteger offset = (NSInteger)(self.collectionView.contentOffset.x / self.collectionView.bounds.size.width) - 1;
195 |
196 | if (offset != 0) {
197 |
198 | self.currentIndex = (self.currentIndex + self.cycleList.count + offset) % self.cycleList.count;
199 |
200 | NSIndexPath *indexPath = [NSIndexPath indexPathForItem:1 inSection:0];
201 | [self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];
202 |
203 | [UIView setAnimationsEnabled:NO];
204 | [self.collectionView reloadItemsAtIndexPaths:@[indexPath]];
205 | [UIView setAnimationsEnabled:YES];
206 |
207 | self.pageControl.currentPage = self.currentIndex;
208 |
209 | }
210 | }
211 | }
212 |
213 | #pragma mark - 定时器相关方法
214 | // 打开定时器启动自动循环播放图片
215 | - (void)timeStart {
216 |
217 | // 1. 创建定时器
218 | self.cycleTimer = [NSTimer timerWithTimeInterval:self.cycleTimeInterval target:self selector:@selector(nextImage) userInfo:nil repeats:true];
219 |
220 | // 2. 添加定时器
221 | [[NSRunLoop currentRunLoop] addTimer:self.cycleTimer forMode:NSRunLoopCommonModes];
222 | }
223 |
224 | // 切换到下一张
225 | - (void)nextImage {
226 |
227 | NSIndexPath *indexPath = [NSIndexPath indexPathForItem: 2 inSection:0];
228 | [self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
229 | }
230 |
231 | - (void)time2Start {
232 |
233 | // 1. 创建定时器
234 | self.cycleTimer2 = [NSTimer timerWithTimeInterval:self.cycleTimeInterval target:self selector:@selector(cycleAnimate) userInfo:nil repeats:true];
235 |
236 | // 2. 添加定时器
237 | [[NSRunLoop currentRunLoop] addTimer:self.cycleTimer2 forMode:NSRunLoopCommonModes];
238 | }
239 |
240 | - (void)cycleAnimate {
241 | if (self.pageControl.currentPage == 0) {
242 | NSIndexPath *indexPath = [NSIndexPath indexPathForItem:1 inSection:0];
243 | [self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
244 | }else {
245 | NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:0];
246 | [self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
247 | }
248 | }
249 |
250 |
251 | // 开始拖拽 停止定时器
252 | - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
253 | if (self.pageControl.numberOfPages == 2) {
254 | [self.cycleTimer2 pauseTimer];
255 | }else if(self.pageControl.numberOfPages > 2){
256 | [self.cycleTimer pauseTimer];
257 | }
258 | // [self.cycleTimer invalidate];
259 | // self.cycleTimer = nil;
260 | }
261 |
262 | // 拖拽停止 添加定时器
263 | - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
264 |
265 | // self.cycleTimer = [NSTimer timerWithTimeInterval:self.cycleTimeInterval target:self selector:@selector(nextImage) userInfo:nil repeats:YES];
266 | //
267 | // [[NSRunLoop currentRunLoop] addTimer:self.cycleTimer forMode:NSRunLoopCommonModes];
268 | if (self.pageControl.numberOfPages == 2) {
269 | [self.cycleTimer2 resumeTimerAfterTimeInterval:self.cycleTimeInterval];
270 | }else if(self.pageControl.numberOfPages > 2){
271 | [self.cycleTimer resumeTimerAfterTimeInterval:self.cycleTimeInterval];
272 | }
273 | }
274 |
275 | // 动画执行完成后执行
276 | - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
277 |
278 | if (self.pageControl.numberOfPages < 3) {
279 | NSInteger offset = (NSInteger)(self.collectionView.contentOffset.x / self.collectionView.bounds.size.width);
280 | self.pageControl.currentPage = offset;
281 | }else {
282 | NSInteger offset = (NSInteger) (self.collectionView.contentOffset.x / self.collectionView.bounds.size.width) - 1;
283 |
284 | if (offset != 0) {
285 |
286 | self.currentIndex = (self.currentIndex + self.cycleList.count + offset) % self.cycleList.count;
287 |
288 | NSIndexPath *indexPath = [NSIndexPath indexPathForItem:1 inSection:0];
289 | [self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];
290 |
291 | [UIView setAnimationsEnabled:NO];
292 | [self.collectionView reloadItemsAtIndexPaths:@[indexPath]];
293 | [UIView setAnimationsEnabled:YES];
294 |
295 | self.pageControl.currentPage = self.currentIndex;
296 | }
297 | }
298 | }
299 |
300 | #pragma mark - 懒加载
301 | // 懒加载返回 UICollectionItems 布局(layout)
302 | - (UICollectionViewFlowLayout *)layout {
303 |
304 | if (!_layout) {
305 | _layout = [[UICollectionViewFlowLayout alloc] init]; // 创建layout
306 | // _layout.itemSize = self.view.bounds.size; // 设置items 大小
307 | _layout.itemSize = CGSizeMake(self.view.frame.size.width, 200); // 设置items 大小
308 | _layout.minimumInteritemSpacing = 0; // 设置最小间距
309 | _layout.minimumLineSpacing = 0; // 设置最小行间距
310 | _layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; // 设置滚动方向
311 | }
312 | return _layout;
313 | }
314 |
315 | @end
316 |
--------------------------------------------------------------------------------
/SDWebImage/SDWebImageManager.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import "SDWebImageCompat.h"
10 | #import "SDWebImageOperation.h"
11 | #import "SDWebImageDownloader.h"
12 | #import "SDImageCache.h"
13 |
14 | typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) {
15 | /**
16 | * By default, when a URL fail to be downloaded, the URL is blacklisted so the library won't keep trying.
17 | * This flag disable this blacklisting.
18 | */
19 | SDWebImageRetryFailed = 1 << 0,
20 |
21 | /**
22 | * By default, image downloads are started during UI interactions, this flags disable this feature,
23 | * leading to delayed download on UIScrollView deceleration for instance.
24 | */
25 | SDWebImageLowPriority = 1 << 1,
26 |
27 | /**
28 | * This flag disables on-disk caching
29 | */
30 | SDWebImageCacheMemoryOnly = 1 << 2,
31 |
32 | /**
33 | * This flag enables progressive download, the image is displayed progressively during download as a browser would do.
34 | * By default, the image is only displayed once completely downloaded.
35 | */
36 | SDWebImageProgressiveDownload = 1 << 3,
37 |
38 | /**
39 | * Even if the image is cached, respect the HTTP response cache control, and refresh the image from remote location if needed.
40 | * The disk caching will be handled by NSURLCache instead of SDWebImage leading to slight performance degradation.
41 | * This option helps deal with images changing behind the same request URL, e.g. Facebook graph api profile pics.
42 | * If a cached image is refreshed, the completion block is called once with the cached image and again with the final image.
43 | *
44 | * Use this flag only if you can't make your URLs static with embeded cache busting parameter.
45 | */
46 | SDWebImageRefreshCached = 1 << 4,
47 |
48 | /**
49 | * In iOS 4+, continue the download of the image if the app goes to background. This is achieved by asking the system for
50 | * extra time in background to let the request finish. If the background task expires the operation will be cancelled.
51 | */
52 | SDWebImageContinueInBackground = 1 << 5,
53 |
54 | /**
55 | * Handles cookies stored in NSHTTPCookieStore by setting
56 | * NSMutableURLRequest.HTTPShouldHandleCookies = YES;
57 | */
58 | SDWebImageHandleCookies = 1 << 6,
59 |
60 | /**
61 | * Enable to allow untrusted SSL ceriticates.
62 | * Useful for testing purposes. Use with caution in production.
63 | */
64 | SDWebImageAllowInvalidSSLCertificates = 1 << 7,
65 |
66 | /**
67 | * By default, image are loaded in the order they were queued. This flag move them to
68 | * the front of the queue and is loaded immediately instead of waiting for the current queue to be loaded (which
69 | * could take a while).
70 | */
71 | SDWebImageHighPriority = 1 << 8,
72 |
73 | /**
74 | * By default, placeholder images are loaded while the image is loading. This flag will delay the loading
75 | * of the placeholder image until after the image has finished loading.
76 | */
77 | SDWebImageDelayPlaceholder = 1 << 9,
78 |
79 | /**
80 | * We usually don't call transformDownloadedImage delegate method on animated images,
81 | * as most transformation code would mangle it.
82 | * Use this flag to transform them anyway.
83 | */
84 | SDWebImageTransformAnimatedImage = 1 << 10,
85 |
86 | /**
87 | * By default, image is added to the imageView after download. But in some cases, we want to
88 | * have the hand before setting the image (apply a filter or add it with cross-fade animation for instance)
89 | * Use this flag if you want to manually set the image in the completion when success
90 | */
91 | SDWebImageAvoidAutoSetImage = 1 << 11
92 | };
93 |
94 | typedef void(^SDWebImageCompletionBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL);
95 |
96 | typedef void(^SDWebImageCompletionWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL);
97 |
98 | typedef NSString *(^SDWebImageCacheKeyFilterBlock)(NSURL *url);
99 |
100 |
101 | @class SDWebImageManager;
102 |
103 | @protocol SDWebImageManagerDelegate
104 |
105 | @optional
106 |
107 | /**
108 | * Controls which image should be downloaded when the image is not found in the cache.
109 | *
110 | * @param imageManager The current `SDWebImageManager`
111 | * @param imageURL The url of the image to be downloaded
112 | *
113 | * @return Return NO to prevent the downloading of the image on cache misses. If not implemented, YES is implied.
114 | */
115 | - (BOOL)imageManager:(SDWebImageManager *)imageManager shouldDownloadImageForURL:(NSURL *)imageURL;
116 |
117 | /**
118 | * Allows to transform the image immediately after it has been downloaded and just before to cache it on disk and memory.
119 | * NOTE: This method is called from a global queue in order to not to block the main thread.
120 | *
121 | * @param imageManager The current `SDWebImageManager`
122 | * @param image The image to transform
123 | * @param imageURL The url of the image to transform
124 | *
125 | * @return The transformed image object.
126 | */
127 | - (UIImage *)imageManager:(SDWebImageManager *)imageManager transformDownloadedImage:(UIImage *)image withURL:(NSURL *)imageURL;
128 |
129 | @end
130 |
131 | /**
132 | * The SDWebImageManager is the class behind the UIImageView+WebCache category and likes.
133 | * It ties the asynchronous downloader (SDWebImageDownloader) with the image cache store (SDImageCache).
134 | * You can use this class directly to benefit from web image downloading with caching in another context than
135 | * a UIView.
136 | *
137 | * Here is a simple example of how to use SDWebImageManager:
138 | *
139 | * @code
140 |
141 | SDWebImageManager *manager = [SDWebImageManager sharedManager];
142 | [manager downloadImageWithURL:imageURL
143 | options:0
144 | progress:nil
145 | completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
146 | if (image) {
147 | // do something with image
148 | }
149 | }];
150 |
151 | * @endcode
152 | */
153 | @interface SDWebImageManager : NSObject
154 |
155 | @property (weak, nonatomic) id delegate;
156 |
157 | @property (strong, nonatomic, readonly) SDImageCache *imageCache;
158 | @property (strong, nonatomic, readonly) SDWebImageDownloader *imageDownloader;
159 |
160 | /**
161 | * The cache filter is a block used each time SDWebImageManager need to convert an URL into a cache key. This can
162 | * be used to remove dynamic part of an image URL.
163 | *
164 | * The following example sets a filter in the application delegate that will remove any query-string from the
165 | * URL before to use it as a cache key:
166 | *
167 | * @code
168 |
169 | [[SDWebImageManager sharedManager] setCacheKeyFilter:^(NSURL *url) {
170 | url = [[NSURL alloc] initWithScheme:url.scheme host:url.host path:url.path];
171 | return [url absoluteString];
172 | }];
173 |
174 | * @endcode
175 | */
176 | @property (nonatomic, copy) SDWebImageCacheKeyFilterBlock cacheKeyFilter;
177 |
178 | /**
179 | * Returns global SDWebImageManager instance.
180 | *
181 | * @return SDWebImageManager shared instance
182 | */
183 | + (SDWebImageManager *)sharedManager;
184 |
185 | /**
186 | * Downloads the image at the given URL if not present in cache or return the cached version otherwise.
187 | *
188 | * @param url The URL to the image
189 | * @param options A mask to specify options to use for this request
190 | * @param progressBlock A block called while image is downloading
191 | * @param completedBlock A block called when operation has been completed.
192 | *
193 | * This parameter is required.
194 | *
195 | * This block has no return value and takes the requested UIImage as first parameter.
196 | * In case of error the image parameter is nil and the second parameter may contain an NSError.
197 | *
198 | * The third parameter is an `SDImageCacheType` enum indicating if the image was retrived from the local cache
199 | * or from the memory cache or from the network.
200 | *
201 | * The last parameter is set to NO when the SDWebImageProgressiveDownload option is used and the image is
202 | * downloading. This block is thus called repetidly with a partial image. When image is fully downloaded, the
203 | * block is called a last time with the full image and the last parameter set to YES.
204 | *
205 | * @return Returns an NSObject conforming to SDWebImageOperation. Should be an instance of SDWebImageDownloaderOperation
206 | */
207 | - (id )downloadImageWithURL:(NSURL *)url
208 | options:(SDWebImageOptions)options
209 | progress:(SDWebImageDownloaderProgressBlock)progressBlock
210 | completed:(SDWebImageCompletionWithFinishedBlock)completedBlock;
211 |
212 | /**
213 | * Saves image to cache for given URL
214 | *
215 | * @param image The image to cache
216 | * @param url The URL to the image
217 | *
218 | */
219 |
220 | - (void)saveImageToCache:(UIImage *)image forURL:(NSURL *)url;
221 |
222 | /**
223 | * Cancel all current opreations
224 | */
225 | - (void)cancelAll;
226 |
227 | /**
228 | * Check one or more operations running
229 | */
230 | - (BOOL)isRunning;
231 |
232 | /**
233 | * Check if image has already been cached
234 | *
235 | * @param url image url
236 | *
237 | * @return if the image was already cached
238 | */
239 | - (BOOL)cachedImageExistsForURL:(NSURL *)url;
240 |
241 | /**
242 | * Check if image has already been cached on disk only
243 | *
244 | * @param url image url
245 | *
246 | * @return if the image was already cached (disk only)
247 | */
248 | - (BOOL)diskImageExistsForURL:(NSURL *)url;
249 |
250 | /**
251 | * Async check if image has already been cached
252 | *
253 | * @param url image url
254 | * @param completionBlock the block to be executed when the check is finished
255 | *
256 | * @note the completion block is always executed on the main queue
257 | */
258 | - (void)cachedImageExistsForURL:(NSURL *)url
259 | completion:(SDWebImageCheckCacheCompletionBlock)completionBlock;
260 |
261 | /**
262 | * Async check if image has already been cached on disk only
263 | *
264 | * @param url image url
265 | * @param completionBlock the block to be executed when the check is finished
266 | *
267 | * @note the completion block is always executed on the main queue
268 | */
269 | - (void)diskImageExistsForURL:(NSURL *)url
270 | completion:(SDWebImageCheckCacheCompletionBlock)completionBlock;
271 |
272 |
273 | /**
274 | *Return the cache key for a given URL
275 | */
276 | - (NSString *)cacheKeyForURL:(NSURL *)url;
277 |
278 | @end
279 |
280 |
281 | #pragma mark - Deprecated
282 |
283 | typedef void(^SDWebImageCompletedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType) __deprecated_msg("Block type deprecated. Use `SDWebImageCompletionBlock`");
284 | typedef void(^SDWebImageCompletedWithFinishedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) __deprecated_msg("Block type deprecated. Use `SDWebImageCompletionWithFinishedBlock`");
285 |
286 |
287 | @interface SDWebImageManager (Deprecated)
288 |
289 | /**
290 | * Downloads the image at the given URL if not present in cache or return the cached version otherwise.
291 | *
292 | * @deprecated This method has been deprecated. Use `downloadImageWithURL:options:progress:completed:`
293 | */
294 | - (id )downloadWithURL:(NSURL *)url
295 | options:(SDWebImageOptions)options
296 | progress:(SDWebImageDownloaderProgressBlock)progressBlock
297 | completed:(SDWebImageCompletedWithFinishedBlock)completedBlock __deprecated_msg("Method deprecated. Use `downloadImageWithURL:options:progress:completed:`");
298 |
299 | @end
300 |
--------------------------------------------------------------------------------
/SDWebImage/UIButton+WebCache.m:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import "UIButton+WebCache.h"
10 | #import "objc/runtime.h"
11 | #import "UIView+WebCacheOperation.h"
12 |
13 | static char imageURLStorageKey;
14 |
15 | @implementation UIButton (WebCache)
16 |
17 | - (NSURL *)sd_currentImageURL {
18 | NSURL *url = self.imageURLStorage[@(self.state)];
19 |
20 | if (!url) {
21 | url = self.imageURLStorage[@(UIControlStateNormal)];
22 | }
23 |
24 | return url;
25 | }
26 |
27 | - (NSURL *)sd_imageURLForState:(UIControlState)state {
28 | return self.imageURLStorage[@(state)];
29 | }
30 |
31 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state {
32 | [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
33 | }
34 |
35 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder {
36 | [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
37 | }
38 |
39 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
40 | [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
41 | }
42 |
43 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock {
44 | [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock];
45 | }
46 |
47 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock {
48 | [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock];
49 | }
50 |
51 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
52 |
53 | [self setImage:placeholder forState:state];
54 | [self sd_cancelImageLoadForState:state];
55 |
56 | if (!url) {
57 | [self.imageURLStorage removeObjectForKey:@(state)];
58 |
59 | dispatch_main_async_safe(^{
60 | NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
61 | if (completedBlock) {
62 | completedBlock(nil, error, SDImageCacheTypeNone, url);
63 | }
64 | });
65 |
66 | return;
67 | }
68 |
69 | self.imageURLStorage[@(state)] = url;
70 |
71 | __weak __typeof(self)wself = self;
72 | id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
73 | if (!wself) return;
74 | dispatch_main_sync_safe(^{
75 | __strong UIButton *sself = wself;
76 | if (!sself) return;
77 | if (image) {
78 | [sself setImage:image forState:state];
79 | }
80 | if (completedBlock && finished) {
81 | completedBlock(image, error, cacheType, url);
82 | }
83 | });
84 | }];
85 | [self sd_setImageLoadOperation:operation forState:state];
86 | }
87 |
88 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state {
89 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
90 | }
91 |
92 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder {
93 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
94 | }
95 |
96 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
97 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
98 | }
99 |
100 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock {
101 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:completedBlock];
102 | }
103 |
104 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock {
105 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:completedBlock];
106 | }
107 |
108 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
109 | [self sd_cancelImageLoadForState:state];
110 |
111 | [self setBackgroundImage:placeholder forState:state];
112 |
113 | if (url) {
114 | __weak __typeof(self)wself = self;
115 | id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
116 | if (!wself) return;
117 | dispatch_main_sync_safe(^{
118 | __strong UIButton *sself = wself;
119 | if (!sself) return;
120 | if (image) {
121 | [sself setBackgroundImage:image forState:state];
122 | }
123 | if (completedBlock && finished) {
124 | completedBlock(image, error, cacheType, url);
125 | }
126 | });
127 | }];
128 | [self sd_setBackgroundImageLoadOperation:operation forState:state];
129 | } else {
130 | dispatch_main_async_safe(^{
131 | NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
132 | if (completedBlock) {
133 | completedBlock(nil, error, SDImageCacheTypeNone, url);
134 | }
135 | });
136 | }
137 | }
138 |
139 | - (void)sd_setImageLoadOperation:(id)operation forState:(UIControlState)state {
140 | [self sd_setImageLoadOperation:operation forKey:[NSString stringWithFormat:@"UIButtonImageOperation%@", @(state)]];
141 | }
142 |
143 | - (void)sd_cancelImageLoadForState:(UIControlState)state {
144 | [self sd_cancelImageLoadOperationWithKey:[NSString stringWithFormat:@"UIButtonImageOperation%@", @(state)]];
145 | }
146 |
147 | - (void)sd_setBackgroundImageLoadOperation:(id)operation forState:(UIControlState)state {
148 | [self sd_setImageLoadOperation:operation forKey:[NSString stringWithFormat:@"UIButtonBackgroundImageOperation%@", @(state)]];
149 | }
150 |
151 | - (void)sd_cancelBackgroundImageLoadForState:(UIControlState)state {
152 | [self sd_cancelImageLoadOperationWithKey:[NSString stringWithFormat:@"UIButtonBackgroundImageOperation%@", @(state)]];
153 | }
154 |
155 | - (NSMutableDictionary *)imageURLStorage {
156 | NSMutableDictionary *storage = objc_getAssociatedObject(self, &imageURLStorageKey);
157 | if (!storage)
158 | {
159 | storage = [NSMutableDictionary dictionary];
160 | objc_setAssociatedObject(self, &imageURLStorageKey, storage, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
161 | }
162 |
163 | return storage;
164 | }
165 |
166 | @end
167 |
168 |
169 | @implementation UIButton (WebCacheDeprecated)
170 |
171 | - (NSURL *)currentImageURL {
172 | return [self sd_currentImageURL];
173 | }
174 |
175 | - (NSURL *)imageURLForState:(UIControlState)state {
176 | return [self sd_imageURLForState:state];
177 | }
178 |
179 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state {
180 | [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
181 | }
182 |
183 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder {
184 | [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
185 | }
186 |
187 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
188 | [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
189 | }
190 |
191 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock {
192 | [self sd_setImageWithURL:url forState:state placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
193 | if (completedBlock) {
194 | completedBlock(image, error, cacheType);
195 | }
196 | }];
197 | }
198 |
199 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock {
200 | [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
201 | if (completedBlock) {
202 | completedBlock(image, error, cacheType);
203 | }
204 | }];
205 | }
206 |
207 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
208 | [self sd_setImageWithURL:url forState:state placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
209 | if (completedBlock) {
210 | completedBlock(image, error, cacheType);
211 | }
212 | }];
213 | }
214 |
215 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state {
216 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:nil];
217 | }
218 |
219 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder {
220 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:nil];
221 | }
222 |
223 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
224 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:nil];
225 | }
226 |
227 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock {
228 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:nil options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
229 | if (completedBlock) {
230 | completedBlock(image, error, cacheType);
231 | }
232 | }];
233 | }
234 |
235 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock {
236 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:0 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
237 | if (completedBlock) {
238 | completedBlock(image, error, cacheType);
239 | }
240 | }];
241 | }
242 |
243 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
244 | [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder options:options completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
245 | if (completedBlock) {
246 | completedBlock(image, error, cacheType);
247 | }
248 | }];
249 | }
250 |
251 | - (void)cancelCurrentImageLoad {
252 | // in a backwards compatible manner, cancel for current state
253 | [self sd_cancelImageLoadForState:self.state];
254 | }
255 |
256 | - (void)cancelBackgroundImageLoadForState:(UIControlState)state {
257 | [self sd_cancelBackgroundImageLoadForState:state];
258 | }
259 |
260 | @end
261 |
--------------------------------------------------------------------------------
/SDWebImage/UIButton+WebCache.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import "SDWebImageCompat.h"
10 | #import "SDWebImageManager.h"
11 |
12 | /**
13 | * Integrates SDWebImage async downloading and caching of remote images with UIButtonView.
14 | */
15 | @interface UIButton (WebCache)
16 |
17 | /**
18 | * Get the current image URL.
19 | */
20 | - (NSURL *)sd_currentImageURL;
21 |
22 | /**
23 | * Get the image URL for a control state.
24 | *
25 | * @param state Which state you want to know the URL for. The values are described in UIControlState.
26 | */
27 | - (NSURL *)sd_imageURLForState:(UIControlState)state;
28 |
29 | /**
30 | * Set the imageView `image` with an `url`.
31 | *
32 | * The download is asynchronous and cached.
33 | *
34 | * @param url The url for the image.
35 | * @param state The state that uses the specified title. The values are described in UIControlState.
36 | */
37 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state;
38 |
39 | /**
40 | * Set the imageView `image` with an `url` and a placeholder.
41 | *
42 | * The download is asynchronous and cached.
43 | *
44 | * @param url The url for the image.
45 | * @param state The state that uses the specified title. The values are described in UIControlState.
46 | * @param placeholder The image to be set initially, until the image request finishes.
47 | * @see sd_setImageWithURL:placeholderImage:options:
48 | */
49 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder;
50 |
51 | /**
52 | * Set the imageView `image` with an `url`, placeholder and custom options.
53 | *
54 | * The download is asynchronous and cached.
55 | *
56 | * @param url The url for the image.
57 | * @param state The state that uses the specified title. The values are described in UIControlState.
58 | * @param placeholder The image to be set initially, until the image request finishes.
59 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
60 | */
61 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
62 |
63 | /**
64 | * Set the imageView `image` with an `url`.
65 | *
66 | * The download is asynchronous and cached.
67 | *
68 | * @param url The url for the image.
69 | * @param state The state that uses the specified title. The values are described in UIControlState.
70 | * @param completedBlock A block called when operation has been completed. This block has no return value
71 | * and takes the requested UIImage as first parameter. In case of error the image parameter
72 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
73 | * indicating if the image was retrived from the local cache or from the network.
74 | * The fourth parameter is the original image url.
75 | */
76 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock;
77 |
78 | /**
79 | * Set the imageView `image` with an `url`, placeholder.
80 | *
81 | * The download is asynchronous and cached.
82 | *
83 | * @param url The url for the image.
84 | * @param state The state that uses the specified title. The values are described in UIControlState.
85 | * @param placeholder The image to be set initially, until the image request finishes.
86 | * @param completedBlock A block called when operation has been completed. This block has no return value
87 | * and takes the requested UIImage as first parameter. In case of error the image parameter
88 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
89 | * indicating if the image was retrived from the local cache or from the network.
90 | * The fourth parameter is the original image url.
91 | */
92 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock;
93 |
94 | /**
95 | * Set the imageView `image` with an `url`, placeholder and custom options.
96 | *
97 | * The download is asynchronous and cached.
98 | *
99 | * @param url The url for the image.
100 | * @param state The state that uses the specified title. The values are described in UIControlState.
101 | * @param placeholder The image to be set initially, until the image request finishes.
102 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
103 | * @param completedBlock A block called when operation has been completed. This block has no return value
104 | * and takes the requested UIImage as first parameter. In case of error the image parameter
105 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
106 | * indicating if the image was retrived from the local cache or from the network.
107 | * The fourth parameter is the original image url.
108 | */
109 | - (void)sd_setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
110 |
111 | /**
112 | * Set the backgroundImageView `image` with an `url`.
113 | *
114 | * The download is asynchronous and cached.
115 | *
116 | * @param url The url for the image.
117 | * @param state The state that uses the specified title. The values are described in UIControlState.
118 | */
119 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state;
120 |
121 | /**
122 | * Set the backgroundImageView `image` with an `url` and a placeholder.
123 | *
124 | * The download is asynchronous and cached.
125 | *
126 | * @param url The url for the image.
127 | * @param state The state that uses the specified title. The values are described in UIControlState.
128 | * @param placeholder The image to be set initially, until the image request finishes.
129 | * @see sd_setImageWithURL:placeholderImage:options:
130 | */
131 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder;
132 |
133 | /**
134 | * Set the backgroundImageView `image` with an `url`, placeholder and custom options.
135 | *
136 | * The download is asynchronous and cached.
137 | *
138 | * @param url The url for the image.
139 | * @param state The state that uses the specified title. The values are described in UIControlState.
140 | * @param placeholder The image to be set initially, until the image request finishes.
141 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
142 | */
143 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
144 |
145 | /**
146 | * Set the backgroundImageView `image` with an `url`.
147 | *
148 | * The download is asynchronous and cached.
149 | *
150 | * @param url The url for the image.
151 | * @param state The state that uses the specified title. The values are described in UIControlState.
152 | * @param completedBlock A block called when operation has been completed. This block has no return value
153 | * and takes the requested UIImage as first parameter. In case of error the image parameter
154 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
155 | * indicating if the image was retrived from the local cache or from the network.
156 | * The fourth parameter is the original image url.
157 | */
158 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock;
159 |
160 | /**
161 | * Set the backgroundImageView `image` with an `url`, placeholder.
162 | *
163 | * The download is asynchronous and cached.
164 | *
165 | * @param url The url for the image.
166 | * @param state The state that uses the specified title. The values are described in UIControlState.
167 | * @param placeholder The image to be set initially, until the image request finishes.
168 | * @param completedBlock A block called when operation has been completed. This block has no return value
169 | * and takes the requested UIImage as first parameter. In case of error the image parameter
170 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
171 | * indicating if the image was retrived from the local cache or from the network.
172 | * The fourth parameter is the original image url.
173 | */
174 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock;
175 |
176 | /**
177 | * Set the backgroundImageView `image` with an `url`, placeholder and custom options.
178 | *
179 | * The download is asynchronous and cached.
180 | *
181 | * @param url The url for the image.
182 | * @param placeholder The image to be set initially, until the image request finishes.
183 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
184 | * @param completedBlock A block called when operation has been completed. This block has no return value
185 | * and takes the requested UIImage as first parameter. In case of error the image parameter
186 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
187 | * indicating if the image was retrived from the local cache or from the network.
188 | * The fourth parameter is the original image url.
189 | */
190 | - (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
191 |
192 | /**
193 | * Cancel the current image download
194 | */
195 | - (void)sd_cancelImageLoadForState:(UIControlState)state;
196 |
197 | /**
198 | * Cancel the current backgroundImage download
199 | */
200 | - (void)sd_cancelBackgroundImageLoadForState:(UIControlState)state;
201 |
202 | @end
203 |
204 |
205 | @interface UIButton (WebCacheDeprecated)
206 |
207 | - (NSURL *)currentImageURL __deprecated_msg("Use `sd_currentImageURL`");
208 | - (NSURL *)imageURLForState:(UIControlState)state __deprecated_msg("Use `sd_imageURLForState:`");
209 |
210 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:`");
211 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:`");
212 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:options:`");
213 |
214 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:completed:`");
215 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:completed:`");
216 | - (void)setImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setImageWithURL:forState:placeholderImage:options:completed:`");
217 |
218 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:`");
219 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:`");
220 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:options:`");
221 |
222 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:completed:`");
223 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:completed:`");
224 | - (void)setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setBackgroundImageWithURL:forState:placeholderImage:options:completed:`");
225 |
226 | - (void)cancelCurrentImageLoad __deprecated_msg("Use `sd_cancelImageLoadForState:`");
227 | - (void)cancelBackgroundImageLoadForState:(UIControlState)state __deprecated_msg("Use `sd_cancelBackgroundImageLoadForState:`");
228 |
229 | @end
230 |
--------------------------------------------------------------------------------