UIGestureRecognizer的子类的实例,每个子类用于查找特定类型的手势,比如清扫、捏合、双击、单击
#import <UIKit/UIKit.h>
@interface>UIViewController
@property (retain, nonatomic) IBOutlet UILabel *label;
@end
#import "liViewController.h"
@interface liViewController ()
@end
@implementation liViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
//添加两个滑动的手势
UISwipeGestureRecognizer *vertical = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(reportVerticalSwipe:)];
vertical.direction = UISwipeGestureRecognizerDirectionUp;
[self.view addGestureRecognizer:vertical];
UISwipeGestureRecognizer *Horizontal = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(reportHorizontalSwipe:)];
Horizontal.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:Horizontal];
}
- (void)reportHorizontalSwipe:(UIGestureRecognizer *)recognither
{
_label.text = @"Horizontal swip detected";
[self performSelector:@selector(eraseText) withObject:nil afterDelay:2];
}
- (void)eraseText
{
_label.text = @"";
}
//实现手势所带来的实际功能
- (void)reportVerticalSwipe:(UIGestureRecognizer *)recgnither
{
_label.text = @"Vertical swipe detected";
[self performSelector:@selector(eraseText) withObject:nil afterDelay:2];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc {
[_label release];
[super dealloc];
}
@end