码迷,mamicode.com
首页 > 其他好文 > 详细

UIGestureRecognizer手势操作

时间:2015-09-20 22:01:32      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:

UIGestureRecognizer类,用来检测,识别用户使用设备时所用的手势,定义了所有手势的基本行为.以下是UIGestureRecognizer子类,哟关于处理具体的用户手势行为。

单击手势

单击手势
UITapGestureRecognizer

UITapGestureRecognizer *singleTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(singleTap:)];
    [self.view addGestureRecognizer:singleTap];
//单击事件
-(void)singleTap:(UITapGestureRecognizer *)tapgestrue
{
    NSLog(@"单击");
}


双击手势

UITapGestureRecognizer
UITapGestureRecognizer *doubleTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doubleTap:)];
    doubleTap.numberOfTapsRequired=2;
    [self.view addGestureRecognizer:doubleTap];
    //区别单击双击手势
    [singleTap requireGestureRecognizerToFail:doubleTap];

//双击点击事件
-(void)doubleTap:(UITapGestureRecognizer *)taggestrue
{
    NSLog(@"双击");
}

轻扫手势

UISwipeGestureRecognizer *swipeGesture=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipe:)];
    //设置轻扫方向,默认向右    swipeGesture.direction=UISwipeGestureRecognizerDirectionDown;
    [self.view addGestureRecognizer:swipeGesture];

//轻扫事件
-(void)swipe:(UISwipeGestureRecognizer *)swipeGesture
{
    NSLog(@"轻扫手势");
}

//平移

UIPanGestureRecognizer *panGesture=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(pan:)];
    [self.view addGestureRecognizer:panGesture];
   //平移事件
-(void)pan:(UIPanGestureRecognizer *)pan
{
    CGPoint point=[pan locationInView:self.view];
    NSLog(@"%@",NSStringFromCGPoint(point));
}

//长按手势

 UILongPressGestureRecognizer *longPressGesture=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];
    longPressGesture.minimumPressDuration=2;
    [self.view addGestureRecognizer:longPressGesture];
//长按手势事件
-(void)longPress:(UILongPressGestureRecognizer *)longPress
{
    //长按离开时一会调用一次,所以需要设置手势状态
    if(longPress.state==UIGestureRecognizerStateEnded)
    {
        return;
    }
    NSLog(@"长按超过两秒");
}    

//旋转手势

UIRotationGestureRecognizer *rotation=[[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotation:)];
    [self.view addGestureRecognizer:rotation];
//旋转事件
-(void)rotation:(UIRotationGestureRecognizer *)rotation
{
    //根据旋转的弧度获得角度
    float degree=rotation.rotation*(180/M_PI);
    NSLog(@"%f",degree);
}

 

UIGestureRecognizer手势操作

标签:

原文地址:http://www.cnblogs.com/kyuubee/p/4824209.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!