No Description

UIImageView+FLAddition.m 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // UIImageView+FLAddition.m
  3. // FirstLink
  4. //
  5. // Created by 王孝道 on 15/5/14.
  6. // Copyright (c) 2015年 FirstLink. All rights reserved.
  7. //
  8. #import "UIImageView+FLAddition.h"
  9. #import "UIImageView+WebCache.h"
  10. #define kAlphaChangeDuration 0.2f
  11. @implementation UIImageView (FLAddition)
  12. - (void)fl_setImageWithURL:(NSURL *)url
  13. {
  14. [self fl_setImageWithURL:url placeholderImage:nil];
  15. }
  16. - (void)fl_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder
  17. {
  18. // WeakSelf(weakSelf);
  19. [self sd_setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  20. // if (!image) { return; }
  21. // [UIView transitionWithView:weakSelf
  22. // duration:kAlphaChangeDuration
  23. // options:UIViewAnimationOptionTransitionCrossDissolve
  24. // animations:^{
  25. // weakSelf.image = image;
  26. // } completion:NULL];
  27. }];
  28. }
  29. - (void)fl_setImageWithURL:(NSString *)urlString finish:(void (^)(CGSize size, NSString *urlString))finishAction
  30. {
  31. WeakSelf(weakSelf);
  32. NSURL *url = [NSURL URLWithString:urlString];
  33. __block typeof(finishAction) weak_finishAction = finishAction;
  34. [self sd_setImageWithURL:url placeholderImage:nil options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
  35. if (!image) {
  36. return;
  37. }
  38. if (weak_finishAction) weak_finishAction(image.size, urlString);
  39. [UIView transitionWithView:weakSelf
  40. duration:kAlphaChangeDuration
  41. options:UIViewAnimationOptionTransitionCrossDissolve
  42. animations:^{
  43. weakSelf.image = image;
  44. } completion:NULL];
  45. }];
  46. }
  47. - (void)setImageWithURL:(NSString *)urlString placeholderImage:(UIImage *)placeholder width:(CGFloat)width height:(CGFloat)height {
  48. NSURL *url;
  49. if ([urlString rangeOfString:@"cdn.firstlinkapp.com"].length > 0) {
  50. url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", urlString,
  51. [FLStringHelper cdnParamaterString:width
  52. height:height]]];
  53. } else {
  54. url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
  55. }
  56. [self fl_setImageWithURL:url placeholderImage:placeholder];
  57. }
  58. - (void)setImageWithURL:(NSString *)urlString cdnWidth:(CGFloat)width {
  59. urlString = [urlString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  60. NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
  61. if ([urlString rangeOfString:@"cdn.firstlinkapp.com"].length > 0) {
  62. url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", urlString, [FLStringHelper cdnParamaterString:width]]];
  63. }
  64. [self fl_setImageWithURL:url placeholderImage:nil];
  65. }
  66. @end