Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changed from using a status NSMutableArray as a queue to using Obj-C …

…Associated Objects.
  • Loading branch information...
commit a871dc7cdee156f97b5c6a23e2794bbc69de35ef 1 parent 383b527
Ash Furrow authored
Showing with 6 additions and 7 deletions.
  1. +6 −7 UIView+ShrinkTo.m
View
13 UIView+ShrinkTo.m
@@ -6,12 +6,13 @@
// Copyright (c) 2012 500px. All rights reserved.
//
-#import "UIView+ShrinkTo.h"
+#import <objc/runtime.h>
#import <QuartzCore/QuartzCore.h>
+#import "UIView+ShrinkTo.h"
@implementation UIView (ShrinkTo)
-static NSMutableArray *queue;
+static NSString *associativeKey = @"associated NSImage";
-(void)shrinkToCenterOfView:(UIView *)targetView
{
@@ -20,8 +21,6 @@ -(void)shrinkToCenterOfView:(UIView *)targetView
-(void)shrinkToPoint:(CGPoint)thePoint inView:(UIView *)theTargetView
{
- if (!queue)
- queue = [[NSMutableArray alloc] init];
UIView *sharedSuperView = self.superview;
while (![theTargetView isDescendantOfView:sharedSuperView])
{
@@ -74,7 +73,7 @@ -(void)shrinkToPoint:(CGPoint)thePoint inView:(UIView *)theTargetView
animGroup.delegate = self;
[imageView.layer addAnimation:animGroup forKey:nil];
- [queue insertObject:imageView atIndex:0];
+ objc_setAssociatedObject(self, &associativeKey, imageView, OBJC_ASSOCIATION_RETAIN);
}
//after we're done animating, we need to remove ourselves from the view so we don't "hang around" on the screen
@@ -82,9 +81,9 @@ - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
if (!flag) return;
- UIImageView *imageView = [queue lastObject];
+ UIImageView *imageView = (UIImageView *)objc_getAssociatedObject(self, &associativeKey);
[imageView removeFromSuperview];
- [queue removeLastObject];
+ objc_setAssociatedObject(self, &associativeKey, nil, OBJC_ASSOCIATION_ASSIGN);
}
@end
Please sign in to comment.
Something went wrong with that request. Please try again.