滑动手势
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic, retain)UISwipeGestureRecognizer *swipeGestureRecognizer;
@end
@implementation ViewController
- (void) handleSwipes:(UISwipeGestureRecognizer *)paramSender{
NSLog(@"paramSender.direction= %d",paramSender.direction);
if (paramSender.direction & UISwipeGestureRecognizerDirectionDown){
NSLog(@"Swiped Down.");
}
if (paramSender.direction & UISwipeGestureRecognizerDirectionLeft){
NSLog(@"Swiped Left.");
}
if (paramSender.direction & UISwipeGestureRecognizerDirectionRight){
NSLog(@"Swiped Right.");
}
if (paramSender.direction & UISwipeGestureRecognizerDirectionUp){
NSLog(@"Swiped Up.");
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
/* Instantiate the object */
self.swipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self
action:@selector(handleSwipes:)];
/* Swipes that are performed from right to left are to be detected */
self.swipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionLeft| UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionUp;
/* Just one finger needed */
self.swipeGestureRecognizer.numberOfTouchesRequired = 1;
/* Add it to the view */
[self.view addGestureRecognizer:self.swipeGestureRecognizer];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
输出:
2014-04-09 15:37:05.210 cookbook[686:a0b] paramSender.direction= 15
2014-04-09 15:37:05.211 cookbook[686:a0b] Swiped Down.
2014-04-09 15:37:05.211 cookbook[686:a0b] Swiped Left.
2014-04-09 15:37:05.212 cookbook[686:a0b] Swiped Right.
2014-04-09 15:37:05.212 cookbook[686:a0b] Swiped Up.
发现只有左右滑有响应,上下滑没响应,不知道是不是我理解有误还是怎么着。懂的人请留言