I am trying to make an app that will match a swipe pattern to display a particular image. Currently i am using buttons to display an image on button click. I want to detect a swipe pattern and display images accordingly. Any help in this direction is welcome. Please help
Asked
Active
Viewed 356 times
-2
-
on button click, click event will happen and on that u will need to do some animation kind of thing, but if u want "swipe effect" then u have to add swipe gesture on button. So just want to suggest that remove this from ur mind that u will get swipe effect on button click.. u need to swipe button.. not click on button – Nayan Jan 20 '14 at 05:54
2 Answers
4
try this one:
.h file add "UIGestureRecognizerDelegate
"
.m file (if you want in self.view)
//LEFT Swipe
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipedLeft:)];
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft ];
[self.view addGestureRecognizer:swipeLeft];
//Right Swipe
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipedRight:)];
[swipeRight setDirection:UISwipeGestureRecognizerDirectionRight ];
[self.view addGestureRecognizer:swipeRight];
//Down Swipe
UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeDown:)];
[swipeDown setDirection:UISwipeGestureRecognizerDirectionDown ];
[self.view addGestureRecognizer:swipeDown];
//Up Swipe
UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeUp:)];
[swipeUp setDirection:UISwipeGestureRecognizerDirectionUp ];
[self.view addGestureRecognizer:swipeUp];
- (void)swipedRight:(UISwipeGestureRecognizer *)recognizer
{ // Do your stuff while swipedRight
}
- (void)swipedLeft:(UISwipeGestureRecognizer *)recognizer
{ // Do your stuff while swipedLeft
}
- (void)swipeDown:(UISwipeGestureRecognizer *)recognizer
{ // Do your stuff while swipeDown
}
- (void)swipeUp:(UISwipeGestureRecognizer *)recognizer
{ // Do your stuff while swipeUp
}
EDIT:
For circular swipe detect:
check answer given by Sixten Otto from here
also check this thread from here
For angle swipe :
check this link
May it will help you.
happy coding...:)

Community
- 1
- 1

Dhaval Bhadania
- 3,090
- 1
- 20
- 35
-
thanks for the help. but i need to check certain swipe patterns.means if user swipes an L,or a square or a circle. Can i do this?? and depending upon the pattern i have to display certain images – slaveCoder Jan 20 '14 at 06:25
-
UISwipeGestureRecognizer gives you only four gesture left,right,up,down.may be you have to use third party library for your requirement and mention question proper way what you want exactly. – Dhaval Bhadania Jan 20 '14 at 06:30
-
i want to detect if a user swiped an L,a square etc. can you please suggest any third party libraries i can look at. – slaveCoder Jan 20 '14 at 06:37
-
1for that check this one: http://stackoverflow.com/questions/1313484/recognizing-patterns-when-drawing-over-the-iphone-screen?rq=1 – Dhaval Bhadania Jan 20 '14 at 06:39
2
Try this
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]
initWithTarget:self
action:@selector(swipeAction)];
swipe.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swipe];
-(void)swipeAction
{
}

Kalpesh
- 5,336
- 26
- 41