2016-06-01 20:53:08 +08:00
|
|
|
/*
|
|
|
|
* This file is part of the SDWebImage package.
|
|
|
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
2012-05-10 06:30:48 +08:00
|
|
|
|
|
|
|
#import "DetailViewController.h"
|
2018-04-19 16:23:17 +08:00
|
|
|
#import <SDWebImage/SDWebImage.h>
|
2012-05-10 06:30:48 +08:00
|
|
|
|
|
|
|
@interface DetailViewController ()
|
2016-06-01 15:06:37 +08:00
|
|
|
|
2017-12-21 11:43:46 +08:00
|
|
|
@property (strong, nonatomic) IBOutlet SDAnimatedImageView *imageView;
|
2024-10-19 23:45:26 +08:00
|
|
|
@property (assign) BOOL tintApplied;
|
2016-06-01 15:06:37 +08:00
|
|
|
|
2012-05-10 06:30:48 +08:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation DetailViewController
|
|
|
|
|
2018-08-29 18:54:48 +08:00
|
|
|
- (void)configureView {
|
2018-01-20 23:40:16 +08:00
|
|
|
if (!self.imageView.sd_imageIndicator) {
|
|
|
|
self.imageView.sd_imageIndicator = SDWebImageProgressIndicator.defaultIndicator;
|
|
|
|
}
|
2017-11-05 06:30:43 +08:00
|
|
|
[self.imageView sd_setImageWithURL:self.imageURL
|
|
|
|
placeholderImage:nil
|
2023-07-12 19:11:01 +08:00
|
|
|
options:SDWebImageProgressiveLoad | SDWebImageScaleDownLargeImages
|
|
|
|
context:@{SDWebImageContextImageForceDecodePolicy: @(SDImageForceDecodePolicyNever)}
|
|
|
|
];
|
2019-11-21 19:17:44 +08:00
|
|
|
self.imageView.shouldCustomLoopCount = YES;
|
2019-11-22 16:16:20 +08:00
|
|
|
self.imageView.animationRepeatCount = 0;
|
2012-05-10 06:30:48 +08:00
|
|
|
}
|
|
|
|
|
2018-08-29 18:54:48 +08:00
|
|
|
- (void)viewDidLoad {
|
2012-05-10 06:30:48 +08:00
|
|
|
[super viewDidLoad];
|
|
|
|
[self configureView];
|
2019-11-05 20:50:13 +08:00
|
|
|
self.navigationItem.rightBarButtonItem = [UIBarButtonItem.alloc initWithTitle:@"Toggle Animation"
|
|
|
|
style:UIBarButtonItemStylePlain
|
|
|
|
target:self
|
|
|
|
action:@selector(toggleAnimation:)];
|
2024-10-19 23:45:26 +08:00
|
|
|
// Add a secret title click action to apply tint color
|
|
|
|
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
|
|
|
|
[button addTarget:self
|
|
|
|
action:@selector(toggleTint:)
|
|
|
|
forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
[button setTitle:@"Tint" forState:UIControlStateNormal];
|
|
|
|
self.navigationItem.titleView = button;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)toggleTint:(UIResponder *)sender {
|
|
|
|
// tint for non-opaque animation
|
|
|
|
if (!self.imageView.isAnimating) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SDAnimatedImage *animatedImage = (SDAnimatedImage *)self.imageView.image;
|
|
|
|
if (animatedImage.sd_imageFormat == SDImageFormatGIF) {
|
|
|
|
// GIF is opaque
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
BOOL containsAlpha = [SDImageCoderHelper CGImageContainsAlpha:animatedImage.CGImage];
|
|
|
|
if (!containsAlpha) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (self.tintApplied) {
|
|
|
|
self.imageView.animationTransformer = nil;
|
|
|
|
} else {
|
|
|
|
self.imageView.animationTransformer = [SDImageTintTransformer transformerWithColor:UIColor.blackColor];
|
|
|
|
}
|
|
|
|
self.tintApplied = !self.tintApplied;
|
|
|
|
// refresh
|
|
|
|
UIImage *image = self.imageView.image;
|
|
|
|
self.imageView.image = nil;
|
|
|
|
self.imageView.image = image;
|
2019-11-05 20:50:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)toggleAnimation:(UIResponder *)sender {
|
|
|
|
self.imageView.isAnimating ? [self.imageView stopAnimating] : [self.imageView startAnimating];
|
2012-05-10 06:30:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|