From c83babe356f4095bddfab63ad1ebbd646c6d7772 Mon Sep 17 00:00:00 2001 From: Guido Sabatini Date: Tue, 20 May 2014 09:43:43 +0200 Subject: [PATCH 1/2] Added delegate methods New methods for the WTUrlImageViewDelegate, allowing to know when the image changes or when the load fail --- .gitignore | 8 + WTURLImageView/WTURLImageView.h | 2 + WTURLImageView/WTURLImageView.m | 12 + .../WTURLImageViewDemo.xccheckout | 39 - WTURLImageViewDemo/WTViewController.h | 3 +- WTURLImageViewDemo/WTViewController.m | 18 + .../en.lproj/WTViewController.xib | 920 +++--------------- 7 files changed, 201 insertions(+), 801 deletions(-) delete mode 100644 WTURLImageViewDemo.xcworkspace/xcshareddata/WTURLImageViewDemo.xccheckout diff --git a/.gitignore b/.gitignore index ea0397b..acef51b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,11 @@ Gemfile.lock Pods Podfile.lock + +WTURLImageViewDemo.xcodeproj/xcuserdata/guidosabatini.xcuserdatad/xcschemes/WTURLImageViewDemo.xcscheme + +WTURLImageViewDemo.xcodeproj/xcuserdata/guidosabatini.xcuserdatad/xcschemes/xcschememanagement.plist + +WTURLImageViewDemo.xcworkspace/xcshareddata/WTURLImageViewDemo.xccheckout + +WTURLImageViewDemo.xcworkspace/xcuserdata/guidosabatini.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist diff --git a/WTURLImageView/WTURLImageView.h b/WTURLImageView/WTURLImageView.h index 36693b5..16dcb0d 100644 --- a/WTURLImageView/WTURLImageView.h +++ b/WTURLImageView/WTURLImageView.h @@ -53,6 +53,8 @@ typedef NS_OPTIONS(NSUInteger, WTURLImageViewOptions) { // with userInteraction is set in the view, user can receive click event @protocol WTURLImageViewDelegate - (void) URLImageViewDidClicked : (WTURLImageView*)imageView; +- (void) URLImageViewDidChangeImageWithSuccess : (WTURLImageView*)imageView; +- (void) URLImageViewDidChangeImageWithFailure : (WTURLImageView*)imageView; @end diff --git a/WTURLImageView/WTURLImageView.m b/WTURLImageView/WTURLImageView.m index a1624a1..3f271d7 100644 --- a/WTURLImageView/WTURLImageView.m +++ b/WTURLImageView/WTURLImageView.m @@ -124,6 +124,10 @@ - (void) endLoadImage : (UIImage*) image { // no image failed if (failedImage) self.image = failedImage; + if ([_delegate respondsToSelector:@selector(URLImageViewDidChangeImageWithFailure:)]) + { + [_delegate URLImageViewDidChangeImageWithFailure:self]; + } return; } @@ -131,10 +135,18 @@ - (void) endLoadImage : (UIImage*) image // scale image image = [self resizedImage:image fillType:fillType]; if ((fromCache && !(options & WTURLImageViewOptionAnimateEvenCache)) || effect==UIViewAnimationOptionTransitionNone) { + if ([_delegate respondsToSelector:@selector(URLImageViewDidChangeImageWithSuccess:)]) + { + [_delegate URLImageViewDidChangeImageWithSuccess:self]; + } self.image = image; } else { // show image with animation + if ([_delegate respondsToSelector:@selector(URLImageViewDidChangeImageWithSuccess:)]) + { + [_delegate URLImageViewDidChangeImageWithSuccess:self]; + } [self wt_makeTransition: image effect:effect]; } } diff --git a/WTURLImageViewDemo.xcworkspace/xcshareddata/WTURLImageViewDemo.xccheckout b/WTURLImageViewDemo.xcworkspace/xcshareddata/WTURLImageViewDemo.xccheckout deleted file mode 100644 index 7bf6499..0000000 --- a/WTURLImageViewDemo.xcworkspace/xcshareddata/WTURLImageViewDemo.xccheckout +++ /dev/null @@ -1,39 +0,0 @@ - - - - - IDESourceControlProjectIdentifier - A6BDF7E2-C779-4E82-B9A5-F164AF866AA8 - IDESourceControlProjectName - WTURLImageViewDemo - IDESourceControlProjectOriginsDictionary - - E144C2CC-6296-43B5-A306-DFA21F314E27 - ssh://github.com/waterlou/WTURLImageView.git - - IDESourceControlProjectPath - WTURLImageViewDemo.xcworkspace - IDESourceControlProjectRelativeInstallPathDictionary - - E144C2CC-6296-43B5-A306-DFA21F314E27 - .. - - IDESourceControlProjectURL - ssh://github.com/waterlou/WTURLImageView.git - IDESourceControlProjectVersion - 110 - IDESourceControlProjectWCCIdentifier - E144C2CC-6296-43B5-A306-DFA21F314E27 - IDESourceControlProjectWCConfigurations - - - IDESourceControlRepositoryExtensionIdentifierKey - public.vcs.git - IDESourceControlWCCIdentifierKey - E144C2CC-6296-43B5-A306-DFA21F314E27 - IDESourceControlWCCName - WTURLImageView - - - - diff --git a/WTURLImageViewDemo/WTViewController.h b/WTURLImageViewDemo/WTViewController.h index 9eb1144..51e1ec7 100644 --- a/WTURLImageViewDemo/WTViewController.h +++ b/WTURLImageViewDemo/WTViewController.h @@ -9,7 +9,7 @@ #import #import "WTURLImageView.h" -@interface WTViewController : UIViewController +@interface WTViewController : UIViewController @property (weak, nonatomic) IBOutlet WTURLImageView *imageView; @@ -20,5 +20,6 @@ - (IBAction)doActivityIndicator:(id)sender; - (IBAction)doTransition:(id)sender; - (IBAction)doResize:(id)sender; +- (IBAction)doSetDelegate:(id)sender; @end diff --git a/WTURLImageViewDemo/WTViewController.m b/WTURLImageViewDemo/WTViewController.m index 0a44994..ff2431a 100644 --- a/WTURLImageViewDemo/WTViewController.m +++ b/WTURLImageViewDemo/WTViewController.m @@ -107,4 +107,22 @@ - (IBAction)doResize:(UISegmentedControl *)sender { } +- (IBAction)doSetDelegate:(UISwitch *)sender { + self.imageView.delegate = sender.isOn ? self : nil; +} + +#pragma mark - WTURLImageViewDelegate + +- (void)URLImageViewDidChangeImageWithSuccess:(WTURLImageView *)imageView +{ + UIAlertView* alert = [[UIAlertView alloc] initWithTitle:nil message:@"Image changed with success" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; + [alert show]; +} + +- (void)URLImageViewDidChangeImageWithFailure:(WTURLImageView *)imageView +{ + UIAlertView* alert = [[UIAlertView alloc] initWithTitle:nil message:@"Image load failed" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; + [alert show]; +} + @end diff --git a/WTURLImageViewDemo/en.lproj/WTViewController.xib b/WTURLImageViewDemo/en.lproj/WTViewController.xib index f643409..815de72 100644 --- a/WTURLImageViewDemo/en.lproj/WTViewController.xib +++ b/WTURLImageViewDemo/en.lproj/WTViewController.xib @@ -1,761 +1,159 @@ - - - - 1552 - 12D78 - 3084 - 1187.37 - 626.00 - - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - 2083 - - - IBProxyObject - IBUIButton - IBUIImageView - IBUILabel - IBUISegmentedControl - IBUISwitch - IBUIView - - - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - - - PluginDependencyRecalculationVersion - - - - - IBFilesOwner - IBCocoaTouchFramework - - - IBFirstResponder - IBCocoaTouchFramework - - - - 274 - - - - 292 - {{80, 20}, {160, 160}} - - - - _NS:9 - NO - IBCocoaTouchFramework - - - - 268 - {{192, 491}, {108, 44}} - - - - _NS:9 - NO - IBCocoaTouchFramework - 0 - 0 - 1 - Load Image - - 3 - MQA - - - 1 - MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA - - - 3 - MC41AA - - - 2 - 15 - - - Helvetica-Bold - 15 - 16 - - - - - 268 - {{219, 283}, {94, 27}} - - - - _NS:9 - NO - IBCocoaTouchFramework - 0 - 0 - YES - - - - 268 - {{10, 286}, {98, 21}} - - - - _NS:9 - NO - YES - 7 - NO - IBCocoaTouchFramework - Place Holder - - 1 - MCAwIDAAA - darkTextColor - - - 0 - - 1 - 17 - - - Helvetica - 17 - 16 - - NO - - - - 268 - {{5, 448}, {310, 30}} - - - - _NS:9 - NO - IBCocoaTouchFramework - 2 - 15 - 0 - - NO - CD - SD - PD - ST - SL - SB - SR - FL - FR - RP - CT - CL - CB - CR - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {0, 0} - {0, 0} - {0, 0} - {0, 0} - {0, 0} - {0, 0} - {0, 0} - {0, 0} - {0, 0} - {0, 0} - {0, 0} - {0, 0} - {0, 0} - {0, 0} - {0, 0} - - - - - - - - - - - - - - - - - - - - - - 268 - {{116, 422}, {88, 21}} - - - - _NS:9 - NO - YES - 7 - NO - IBCocoaTouchFramework - Transition - - - 0 - 1 - - - NO - - - - 268 - {{10, 319}, {213, 21}} - - - - _NS:9 - NO - YES - 7 - NO - IBCocoaTouchFramework - Clear Image Before Loading - - - 0 - - - NO - - - - 268 - {{219, 316}, {94, 27}} - - - - _NS:9 - NO - IBCocoaTouchFramework - 0 - 0 - YES - - - - 268 - {{10, 354}, {85, 21}} - - - - _NS:9 - NO - YES - 7 - NO - IBCocoaTouchFramework - Use Cache - - - 0 - - - NO - - - - 268 - {{219, 351}, {94, 27}} - - - - _NS:9 - NO - IBCocoaTouchFramework - 0 - 0 - YES - - - - 268 - {{10, 388}, {204, 21}} - - - - _NS:9 - NO - YES - 7 - NO - IBCocoaTouchFramework - Activity Indicator - - - 0 - - - NO - - - - 268 - {{219, 385}, {94, 27}} - - - - _NS:9 - NO - IBCocoaTouchFramework - 0 - 0 - YES - - - - 268 - {{6, 505}, {170, 30}} - - - - _NS:9 - NO - 5000 - IBCocoaTouchFramework - 2 - 3 - 0 - - Stretch - Fill-in - Fit-in - - - - - - - - - - - - - {0, 0} - {0, 0} - {0, 0} - - - - - - - - - - 268 - {{48, 482}, {88, 21}} - - - - _NS:9 - NO - YES - 7 - NO - IBCocoaTouchFramework - Resize - - - 0 - 1 - - - NO - - - {{0, 20}, {320, 548}} - - - - - 3 - MC43NQA - - 2 - - - NO - - - IBUIScreenMetrics - - YES - - - - - - {320, 568} - {568, 320} - - - IBCocoaTouchFramework - Retina 4 Full Screen - 2 - - IBCocoaTouchFramework - - - - - - - view - - - - 7 - - - - imageView - - - - 17 - - - - doLoadImage: - - - 7 - - 22 - - - - doUsePlaceHolder: - - - 13 - - 178 - - - - doTransition: - - - 13 - - 174 - - - - doClearImageBeforeLoading: - - - 13 - - 177 - - - - doUseDiskCache: - - - 13 - - 176 - - - - doActivityIndicator: - - - 13 - - 175 - - - - doResize: - - - 13 - - 181 - - - - - - 0 - - - - - - -1 - - - File's Owner - - - -2 - - - - - 6 - - - - - - - - - - - - - - - - - - - - - 8 - - - - - - 18 - - - - - 33 - - - - - 36 - - - - - - 45 - - - - - - 65 - - - - - - 91 - - - - - 94 - - - - - 148 - - - - - 149 - - - - - 159 - - - - - 160 - - - - - 179 - - - - - 180 - - - - - - - WTViewController - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - UIResponder - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - WTURLImageView - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - - - - - - 181 - - - - - WTURLImageView - UIImageView - - IBProjectSource - ./Classes/WTURLImageView.h - - - - WTViewController - UIViewController - - id - id - id - id - id - id - id - - - - doActivityIndicator: - id - - - doClearImageBeforeLoading: - id - - - doLoadImage: - id - - - doResize: - id - - - doTransition: - id - - - doUseDiskCache: - id - - - doUsePlaceHolder: - id - - - - imageView - WTURLImageView - - - imageView - - imageView - WTURLImageView - - - - IBProjectSource - ./Classes/WTViewController.h - - - - - 0 - IBCocoaTouchFramework - YES - 3 - 2083 - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 0fccb5bf84229a971d4c22a1e8af4f255a4f1d94 Mon Sep 17 00:00:00 2001 From: Guido Sabatini Date: Mon, 26 May 2014 17:08:26 +0200 Subject: [PATCH 2/2] Better implementation Now successful image change passes also the new image --- WTURLImageView/WTURLImageView.h | 6 +++--- WTURLImageView/WTURLImageView.m | 16 ++++++++-------- WTURLImageViewDemo/WTViewController.m | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/WTURLImageView/WTURLImageView.h b/WTURLImageView/WTURLImageView.h index 16dcb0d..5cf69e8 100644 --- a/WTURLImageView/WTURLImageView.h +++ b/WTURLImageView/WTURLImageView.h @@ -38,7 +38,7 @@ typedef NS_OPTIONS(NSUInteger, WTURLImageViewOptions) { WTURLImageViewOptionTransitionFlipFromLeft = 8 << 20, WTURLImageViewOptionTransitionFlipFromRight = 9 << 20, - + WTURLImageViewOptionTransitionRipple = 10 << 20, WTURLImageViewOptionTransitionCubeFromTop = 11 << 20, WTURLImageViewOptionTransitionCubeFromLeft = 12 << 20, @@ -53,8 +53,8 @@ typedef NS_OPTIONS(NSUInteger, WTURLImageViewOptions) { // with userInteraction is set in the view, user can receive click event @protocol WTURLImageViewDelegate - (void) URLImageViewDidClicked : (WTURLImageView*)imageView; -- (void) URLImageViewDidChangeImageWithSuccess : (WTURLImageView*)imageView; -- (void) URLImageViewDidChangeImageWithFailure : (WTURLImageView*)imageView; +- (void) URLImageView:(WTURLImageView*)imageView didChangeImageWithSuccess:(UIImage*)newImage; +- (void) URLImageViewDidChangeImageWithFailure:(WTURLImageView*)imageView; @end diff --git a/WTURLImageView/WTURLImageView.m b/WTURLImageView/WTURLImageView.m index 3f271d7..20d6c59 100644 --- a/WTURLImageView/WTURLImageView.m +++ b/WTURLImageView/WTURLImageView.m @@ -119,7 +119,7 @@ - (void) endLoadImage : (UIImage*) image UIActivityIndicatorView *aiv = [self activityIndicator]; [aiv stopAnimating]; } - + if (image==nil) { // no image failed @@ -135,19 +135,19 @@ - (void) endLoadImage : (UIImage*) image // scale image image = [self resizedImage:image fillType:fillType]; if ((fromCache && !(options & WTURLImageViewOptionAnimateEvenCache)) || effect==UIViewAnimationOptionTransitionNone) { - if ([_delegate respondsToSelector:@selector(URLImageViewDidChangeImageWithSuccess:)]) + self.image = image; + if ([_delegate respondsToSelector:@selector(URLImageView:didChangeImageWithSuccess:)]) { - [_delegate URLImageViewDidChangeImageWithSuccess:self]; + [_delegate URLImageView:self didChangeImageWithSuccess:image]; } - self.image = image; } else { // show image with animation - if ([_delegate respondsToSelector:@selector(URLImageViewDidChangeImageWithSuccess:)]) + [self wt_makeTransition: image effect:effect]; + if ([_delegate respondsToSelector:@selector(URLImageView:didChangeImageWithSuccess:)]) { - [_delegate URLImageViewDidChangeImageWithSuccess:self]; + [_delegate URLImageView:self didChangeImageWithSuccess:image]; } - [self wt_makeTransition: image effect:effect]; } } @@ -269,7 +269,7 @@ - (void) setURL:(NSURL*)url withPreset:(WTURLImageViewPreset*) preset options:preset.options placeholderImage:preset.placeholderImage failedImage:preset.failedImage - diskCacheTimeoutInterval:preset.diskCacheTimeInterval]; +diskCacheTimeoutInterval:preset.diskCacheTimeInterval]; } - (void) reloadWithPreset : (WTURLImageViewPreset*)preset diff --git a/WTURLImageViewDemo/WTViewController.m b/WTURLImageViewDemo/WTViewController.m index ff2431a..bfd9e0f 100644 --- a/WTURLImageViewDemo/WTViewController.m +++ b/WTURLImageViewDemo/WTViewController.m @@ -113,7 +113,7 @@ - (IBAction)doSetDelegate:(UISwitch *)sender { #pragma mark - WTURLImageViewDelegate -- (void)URLImageViewDidChangeImageWithSuccess:(WTURLImageView *)imageView +- (void)URLImageView:(WTURLImageView *)imageView didChangeImageWithSuccess:(UIImage *)newImage { UIAlertView* alert = [[UIAlertView alloc] initWithTitle:nil message:@"Image changed with success" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show];