首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Iphone >

【iPhone代码片断之四】手势识别器的用法

2012-09-06 
【iPhone代码片段之四】手势识别器的用法swipe对应手势识别器是UISwipeGestureRecognizer,示例代码如下:- (v

【iPhone代码片段之四】手势识别器的用法

swipe对应手势识别器是UISwipeGestureRecognizer,示例代码如下:

- (void)viewDidLoad{    [super viewDidLoad];// Do any additional setup after loading the view, typically from a nib.    label.text=@"";    //注册GestureRecognizer    //注册上下手势    UISwipeGestureRecognizer *vertical = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(reportVerticalSwipe:)];    vertical.direction = UISwipeGestureRecognizerDirectionUp|UISwipeGestureRecognizerDirectionDown;    [self.view addGestureRecognizer:vertical];        //注册左右手势    UISwipeGestureRecognizer *horizontal = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(reportHoriziontalSwipe:)];    horizontal.direction = UISwipeGestureRecognizerDirectionLeft|UISwipeGestureRecognizerDirectionRight;    [self.view addGestureRecognizer:horizontal];}-(void)reportHoriziontalSwipe:(UIGestureRecognizer *)recognizer{    label.text = @"左右滑动";    [self performSelector:@selector(eraseText) withObject:nil afterDelay:2];}-(void)reportVerticalSwipe:(UIGestureRecognizer *)recognizer{    label.text = @"上下滑动";    [self performSelector:@selector(eraseText) withObject:nil afterDelay:2];}-(void)eraseText{    label.text = @"";}

Tap对应UITapGestureRecognizer

Pinch对应UIPinchGestureRecognizer

使用方法与上述示例大同小异。


热点排行