mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-22 06:03:45 +00:00
Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run: git remote add om-historic [om-historic.git repo url] git fetch --tags om-historic git replace squashed-history historic-commits
This commit is contained in:
46
iphone/Maps/Core/WebImage/UIImageView+WebImage.m
Normal file
46
iphone/Maps/Core/WebImage/UIImageView+WebImage.m
Normal file
@@ -0,0 +1,46 @@
|
||||
#import "UIImageView+WebImage.h"
|
||||
#import "MWMWebImage.h"
|
||||
|
||||
#import <objc/runtime.h>
|
||||
|
||||
static char kAssociatedObjectKey;
|
||||
|
||||
@implementation UIImageView (WebImage)
|
||||
|
||||
- (void)wi_setImageWithUrl:(NSURL *)url {
|
||||
[self wi_setImageWithUrl:url transitionDuration:0 completion:nil];
|
||||
}
|
||||
|
||||
- (void)wi_setImageWithUrl:(NSURL *)url
|
||||
transitionDuration:(NSTimeInterval)duration
|
||||
completion:(void (^)(UIImage *, NSError *))completion {
|
||||
id<IMWMImageTask> task = [[MWMWebImage defaultWebImage] imageWithUrl:url
|
||||
completion:^(UIImage *image, NSError *error) {
|
||||
objc_setAssociatedObject(self, &kAssociatedObjectKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
if (!image) {
|
||||
if (completion) { completion(nil, error); }
|
||||
return;
|
||||
}
|
||||
|
||||
if (duration > 0) {
|
||||
[UIView transitionWithView:self
|
||||
duration:duration
|
||||
options:UIViewAnimationOptionTransitionCrossDissolve
|
||||
animations:^{ self.image = image; }
|
||||
completion:nil];
|
||||
} else {
|
||||
self.image = image;
|
||||
}
|
||||
|
||||
if (completion) { completion(image, nil); }
|
||||
}];
|
||||
objc_setAssociatedObject(self, &kAssociatedObjectKey, task, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
}
|
||||
|
||||
- (void)wi_cancelImageRequest {
|
||||
id<IMWMImageTask> task = objc_getAssociatedObject(self, &kAssociatedObjectKey);
|
||||
[task cancel];
|
||||
objc_setAssociatedObject(self, &kAssociatedObjectKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user