HardBirch

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

时间:12-08-08 栏目:iOS移动应用开发技术 作者:张飞不张,文采横飞 评论:0 点击: 1,170 次

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

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

声明: 本文由( 张飞不张,文采横飞 )原创编译,转载请保留链接: 【iPhone代码片段之四】手势识别器的用法

【iPhone代码片段之四】手势识别器的用法:等您坐沙发呢!

发表评论


QQ群互动

Linux系统与内核学习群:194051772

WP建站技术学习交流群:194062106

魔豆之路QR

魔豆的Linux内核之路

魔豆的Linux内核之路

优秀工程师当看优秀书籍

优秀程序员,要看优秀书!

赞助商广告

友荐云推荐