Update the example with toggle animation button

This commit is contained in:
DreamPiggy 2019-11-05 20:50:13 +08:00
parent 64b4c24535
commit aa3d2225db
2 changed files with 28 additions and 0 deletions

View File

@ -29,6 +29,14 @@
- (void)viewDidLoad {
[super viewDidLoad];
[self configureView];
self.navigationItem.rightBarButtonItem = [UIBarButtonItem.alloc initWithTitle:@"Toggle Animation"
style:UIBarButtonItemStylePlain
target:self
action:@selector(toggleAnimation:)];
}
- (void)toggleAnimation:(UIResponder *)sender {
self.imageView.isAnimating ? [self.imageView stopAnimating] : [self.imageView startAnimating];
}
@end

View File

@ -34,16 +34,27 @@
// NSImageView + Static Image
self.imageView1.sd_imageIndicator = SDWebImageProgressIndicator.defaultIndicator;
[self.imageView1 sd_setImageWithURL:[NSURL URLWithString:@"https://raw.githubusercontent.com/recurser/exif-orientation-examples/master/Landscape_2.jpg"] placeholderImage:nil options:SDWebImageProgressiveLoad];
// NSImageView + Animated Image
self.imageView2.sd_imageIndicator = SDWebImageActivityIndicator.largeIndicator;
[self.imageView2 sd_setImageWithURL:[NSURL URLWithString:@"https:raw.githubusercontent.com/onevcat/APNGKit/master/TestImages/APNG-cube.apng"]];
NSMenu *menu1 = [[NSMenu alloc] initWithTitle:@"Toggle Animation"];
NSMenuItem *item1 = [menu1 addItemWithTitle:@"Toggle Animation" action:@selector(toggleAnimation:) keyEquivalent:@""];
item1.tag = 1;
self.imageView2.menu = menu1;
// SDAnimatedImageView + Static Image
[self.imageView3 sd_setImageWithURL:[NSURL URLWithString:@"https://nr-platform.s3.amazonaws.com/uploads/platform/published_extension/branding_icon/275/AmazonS3.png"]];
// SDAnimatedImageView + Animated Image
self.imageView4.sd_imageTransition = SDWebImageTransition.fadeTransition;
self.imageView4.imageScaling = NSImageScaleProportionallyUpOrDown;
self.imageView4.imageAlignment = NSImageAlignLeft; // supports NSImageView's layout properties
[self.imageView4 sd_setImageWithURL:[NSURL URLWithString:@"http://littlesvr.ca/apng/images/SteamEngine.webp"] placeholderImage:nil options:SDWebImageForceTransition];
NSMenu *menu2 = [[NSMenu alloc] initWithTitle:@"Toggle Animation"];
NSMenuItem *item2 = [menu2 addItemWithTitle:@"Toggle Animation" action:@selector(toggleAnimation:) keyEquivalent:@""];
item2.tag = 2;
self.imageView4.menu = menu2;
self.clearCacheButton.target = self;
self.clearCacheButton.action = @selector(clearCacheButtonClicked:);
@ -60,6 +71,15 @@
}];
}
- (void)toggleAnimation:(NSMenuItem *)sender {
NSImageView *imageView = sender.tag == 1 ? self.imageView2 : self.imageView4;
if (imageView.animates) {
imageView.animates = NO;
} else {
imageView.animates = YES;
}
}
- (void)setRepresentedObject:(id)representedObject {
[super setRepresentedObject:representedObject];