1

I am creating application that having Quotes in Property list and it is display in UIText when i press next button another quotes comes in textview but now i want to add gesture to it when user swipe left or right accordance to that action quotes would be come . I am new to iphone . I Have done it in android using viewpagger. Would any body have idea about this how can i make it.. thanks in advance.

  • Not sure I follow your question 100%. Does the accepted answer to this question help you? http://stackoverflow.com/questions/4279699/how-to-detect-swipe-gesture-in-iphone-sdk – Carl Veazey Apr 01 '13 at 05:52

2 Answers2

2

You can do it by using UISwipeGestureRecognizer. Make sure your textView is not editable.

Code as below :

UISwipeGestureRecognizer *leftSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipe)];
[leftSwipe setDirection:UISwipeGestureRecognizerDirectionLeft];
[_textView addGestureRecognizer:leftSwipe];


UISwipeGestureRecognizer *rightSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipe)];
[rightSwipe setDirection:UISwipeGestureRecognizerDirectionRight];
[_textView addGestureRecognizer:rightSwipe];

- (void) leftSwipe
{
    NSLog(@"leftSwipe");
}

- (void) rightSwipe
{
    NSLog(@"rightSwipe");
}

Now show your quotes accordingly.

Prashant Bhayani
  • 692
  • 5
  • 18
0

To give animation to your quotes :

First of all import QuartzCore framework to you project.

#import <QuartzCore/QuartzCore.h>

Now modify swipe methods as below :

- (void) leftSwipe
{
NSLog(@"leftSwipe");

[self curlAnimationFromLeft];
}

- (void) rightSwipe
{
NSLog(@"rightSwipe");

[self curlAnimationFromRight];
}


- (void) curlAnimationFromLeft
{
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setDuration:1.0];
[animation setTimingFunction:UIViewAnimationCurveEaseInOut];
animation.type = @"pageCurl";
animation.subtype = @"fromRight";
animation.fillMode = kCAFillModeForwards;
[animation setRemovedOnCompletion:YES];
[_textView.layer addAnimation:animation forKey:@"pageCurlAnimation"];
}

-(void)curlAnimationFromRight
{
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setDuration:1.0];
[animation setTimingFunction:UIViewAnimationCurveEaseInOut];
animation.type = @"pageUnCurl";
animation.subtype = @"fromRight";
animation.fillMode = kCAFillModeForwards;
animation.startProgress = 0.35;
[animation setRemovedOnCompletion:NO];
[_textView.layer addAnimation:animation forKey:@"pageUnCurlAnimation"];
}
Prashant Bhayani
  • 692
  • 5
  • 18
  • Prashant,i am getting error near around animation setTimingFunction:UIViewAnimationCurveEaseInOut , It says implicit conversion NSinteger. –  Apr 01 '13 at 07:09
  • have you added framework? – Prashant Bhayani Apr 01 '13 at 07:21
  • yes i have added –  Apr 01 '13 at 07:35
  • is the file that you might have imported in .m file. but have added framework for it? – Prashant Bhayani Apr 01 '13 at 08:35
  • Yes i have added the framework even though there is an error i think i am using ARC (Automatic Retain count) is there is any problem with that . i have removed that line error is gone now so what is befit to add that function –  Apr 01 '13 at 09:00
  • 1
    i found the solution instead of the function i have added this because it ARC version [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]]; –  Apr 02 '13 at 04:24