In .h file
Add Protocol for Recognize SwipeGesture
BOOL transitioning; // This Bool Variable for Swipe complete functionality
@property (nonatomic) BOOL transitioning;
//FOR Transitioning
- (void)reloadData:(BOOL)animated andSwipe : (NSString *)side;
In .m file
@synthesize transitioning;
#import
This framework is for CoreAnimation
//IN VIEW_DID_LOAD
//Add a left swipe gesture recognizer
UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeLeft:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[self.storeDetailTblView addGestureRecognizer:recognizer];
[recognizer release];
//Add a right swipe gesture recognizer
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeRight:)];
recognizer.delegate = self;
[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[self.storeDetailTblView addGestureRecognizer:recognizer];
[recognizer release];
#pragma mark swipe
- (void)handleSwipeRight:(UISwipeGestureRecognizer *)gestureRecognizer
{
//Get location of the swipe
CGPoint location = [gestureRecognizer locationInView:YOUR_TABLEVIEW];
NSLog(@"RIGHT ---- Touch point coordinates are : %f - %f", location.x , location.y);
if(!self.transitioning)
{
[self reloadData:YES andSwipe:@"RIGHT"];
}
}
- (void)handleSwipeLeft:(UISwipeGestureRecognizer *)gestureRecognizer
{
//Get location of the swipe
CGPoint location = [gestureRecognizer locationInView:self.storeDetailTblView];
NSLog(@"LEFT ---- Touch point coordinates are : %f - %f", location.x , location.y);
if(!self.transitioning)
{
[self reloadData:YES andSwipe:@"LEFT"];
}
}
- (void)reloadData:(BOOL)animated andSwipe : (NSString *)side
{
if (animated) {
// First create a CATransition object to describe the transition
CATransition *animation = [CATransition animation];
// Animate over 3/4 of a second
animation.duration = 0.75;
// using the ease in/out timing function
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.delegate = self; // optional
animation.type = kCATransitionPush;
if ([side isEqualToString:@"LEFT"]){
// Now to set the type of transition.
animation.subtype = kCATransitionFromRight;
//
if (YOUR_INDEX == [YOUR_ARRAY count] -1) {
DLog(@"ARRAY Index OUT oF BOUND");
return;
}
YOUR_INDEX=YOUR_INDEX+1;
//
}
else{
if (YOUR_INDEX == 0) {
DLog(@"ARRAY Index == 0");
return;
}
animation.subtype = kCATransitionFromLeft;
YOUR_INDEX=YOUR_INDEX-1;
}
id someStore= [YOUR_ARRAY objectAtIndex:YOUR_INDEX];
if ([someStore isKindOfClass:[NSDictionary class]] == NO)
{
// NSAssert(NO, @"Expected a dictionary, got %@", NSStringFromClass([someStore class]));
}
NSDictionary *storeDictionary = someStore;
YOUR_DICTIONARY = storeDictionary;
// Finally, to avoid overlapping transitions we assign ourselves as the delegate for the animation and wait for the
// -animationDidStop:finished: message. When it comes in, we will flag that we are no longer transitioning.
self.transitioning = YES;
[YOUR_TABLEVIEW.layer addAnimation:animation forKey:nil];
[YOUR_TABLEVIEW reloadData];
}
}
-(void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
{
DLog(@"STOP_TRANSITIONING");
self.transitioning = NO;
}
OUTPUT
This Tableview is Populate with YOUR_ARRAY.If you want to see detail of an object on particular index.
On next view you see all objects swiping your view. Handling is also done.
Only thing is when you adding a view on tableview, you must assign list array to YOUR_ARRAY and index too to YOUR_INDEX.
This Code Really helps for me.
Thanks to
Mr. Praveen Garg
gargpraveen.blogspot.com
No comments:
Post a Comment