Created
August 5, 2010 07:57
-
-
Save jankeesvw/509407 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UISwipableTableCell.m | |
// GameKings | |
// | |
// Created by Jankees van Woezik on 2-8-10. | |
// Copyright 2010 Base 42. All rights reserved. | |
// | |
#import "UISwipableTableViewCell.h" | |
@implementation UISwipableTableViewCell | |
@synthesize frontCell; | |
@synthesize backCell; | |
@synthesize backCellIsVisible; | |
@synthesize delegate; | |
-(void)awakeFromNib | |
{ | |
//// Swipe left: | |
// Create swipe recognizer and set its direction | |
swipeRecognizerLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeToLeft:)]; | |
swipeRecognizerLeft.direction = UISwipeGestureRecognizerDirectionLeft; | |
NSLog(@"Swipe swipeRecognizerLeft, %@",swipeRecognizerLeft); | |
// Add recognizer to the foreground view | |
[frontCell addGestureRecognizer:swipeRecognizerLeft]; | |
//// Swipe Right: | |
// Create swipe recognizer and set its direction | |
swipeRecognizerRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeToRight:)]; | |
swipeRecognizerRight.direction = UISwipeGestureRecognizerDirectionRight; | |
// Add recognizer to the foreground view | |
[backCell addGestureRecognizer:swipeRecognizerRight]; | |
// Disbale the blue color | |
[self setSelectionStyle:UITableViewCellSelectionStyleNone]; | |
// Call super function | |
[super awakeFromNib]; | |
} | |
- (void)dealloc | |
{ | |
NSLog(@"Swipe dealloc"); | |
// Release swipe | |
[frontCell removeGestureRecognizer:swipeRecognizerLeft]; | |
[backCell removeGestureRecognizer:swipeRecognizerRight]; | |
[swipeRecognizerRight release]; | |
[swipeRecognizerLeft release]; | |
// Release cells | |
[frontCell release]; | |
[backCell release]; | |
[super dealloc]; | |
} | |
#pragma mark - | |
#pragma mark Swipe implementation | |
- (void)didSwipeToLeft:(UISwipeGestureRecognizer *)recognizer | |
{ | |
NSLog(@"Swipe didSwipeToLeft"); | |
// Reveal the background when the swipe is detected | |
[self makeBackCellVisible:YES]; | |
} | |
- (void)didSwipeToRight:(UISwipeGestureRecognizer *)recognizer | |
{ | |
NSLog(@"Swipe didSwipeToRight"); | |
// Reveal the background when the swipe is detected | |
[self makeBackCellVisible:NO]; | |
} | |
- (void)makeBackCellVisible:(BOOL)visible | |
{ | |
NSLog(@"Swipe makeBackCellVisible, %i",visible); | |
// Set property | |
backIsVisible = visible; | |
// Animate frontCell | |
[UIView beginAnimations:nil context:nil]; | |
[UIView setAnimationDuration:0.2]; | |
[UIView setAnimationDelay:0]; | |
[UIView setAnimationDelegate:delegate]; | |
if ( visible == YES ) | |
{ | |
[delegate backCellWillAppear:self]; | |
[UIView setAnimationDidStopSelector:@selector(backCellDidAppear:)]; | |
frontCell.transform = CGAffineTransformMakeTranslation( -360, 0 ); | |
} | |
else | |
{ | |
frontCell.transform = CGAffineTransformMakeTranslation( 0, 0 ); | |
} | |
[UIView commitAnimations]; | |
} | |
- (BOOL)backCellIsVisible | |
{ | |
return backIsVisible; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment