Skip to content

Instantly share code, notes, and snippets.

@jonfriskics
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonfriskics/c5cacf15bf2247e740e6 to your computer and use it in GitHub Desktop.
Save jonfriskics/c5cacf15bf2247e740e6 to your computer and use it in GitHub Desktop.
Animations that persist in cells (sort of)
//
// AVRAnimatedTableViewController.m
// AnimationIssues
//
// Created by Adam Weeks on 5/2/14.
// Copyright (c) 2014 AppsVersusRobots, LLC. All rights reserved.
//
#import "AVRAnimatedTableViewController.h"
#import "AVRAnimatedTableViewCell.h"
@import QuartzCore;
#define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI)
@implementation AVRAnimatedTableViewController
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 30;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
AVRAnimatedTableViewCell *cell = (AVRAnimatedTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"animatedCell" forIndexPath:indexPath];
return cell;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
AVRAnimatedTableViewCell *aCell = (AVRAnimatedTableViewCell *)cell;
NSLog(@"will display cell %d",indexPath.row);
if(aCell.layer.animationKeys.count > 0) {
[aCell.loadingImageView.layer removeAllAnimations];
}
[UIView animateWithDuration:0.75 delay:1.0 options:(UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionCurveLinear | UIViewAnimationOptionRepeat) animations:^{
NSLog(@"in here %d",indexPath.row);
aCell.loadingImageView.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(90));
NSLog(@"%d keys %@",indexPath.row,aCell.loadingImageView.layer.animationKeys);
} completion:^(BOOL finished) {
}];
}
- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"end display cell %d",indexPath.row);
}
@end
//
// AVRAnimatedTableViewCell.h
// AnimationIssues
//
// Created by Adam Weeks on 5/2/14.
// Copyright (c) 2014 AppsVersusRobots, LLC. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface AVRAnimatedTableViewCell : UITableViewCell
@property (strong, nonatomic) IBOutlet UIImageView *loadingImageView;
@end
//
// AVRAnimatedTableViewCell.m
// AnimationIssues
//
// Created by Adam Weeks on 5/2/14.
// Copyright (c) 2014 AppsVersusRobots, LLC. All rights reserved.
//
#import "AVRAnimatedTableViewCell.h"
@implementation AVRAnimatedTableViewCell
- (void)prepareForReuse
{
[self setNeedsDisplay];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment