IOS手指触摸滑动

主要是捕捉3个事件,触摸开始touchesBegan,触摸移动touchesMoved,触摸结束touchesEnded。

//滑动开始事件
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//    NSLog(@"开始了");
    UITouch *touch = [touches anyObject];
    CGPoint pointone = [touch locationInView:self.view];//获得初始的接触点
    //以字符的形式输出触摸点
    
    
    _startX  = pointone.x;
    NSLog(@"触摸点的坐标:%f",_startX);
}
//滑动移动事件
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
//    NSLog(@"移动啦");
    UITouch *touch = [touches anyObject];
    //imgViewTop是滑动后最后接触的View
    CGPoint pointtwo = [touch locationInView:self.view];  //获得滑动后最后接触屏幕的点
     NSLog(@"移动点的坐标:%f,%f",pointtwo.x,_startX);
    int position = (pointtwo.x-_startX);
    NSLog(@"position is %d",position);
    if(fabs(pointtwo.x-_startX)>100)
    {  //判断两点间的距离
        NSLog(@"移动了");
         _bMove = YES;
    }
}

//滑动结束处理事件
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint pointtwo = [touch locationInView:self.view];  //获得滑动后最后接触屏幕的点
    if((fabs(pointtwo.x-_startX)>50)&&(_bMove))
    {
        //判断点的位置关系 左滑动
        if(pointtwo.x-_startX>0)
        {   //左向右滑动业务处理
            NSLog(@"左向右移动");
          
        }
        //判断点的位置关系 右滑动
        else
        {  //右向左滑动业务处理
            NSLog(@"右移动");
             [self goToNext];
        }
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值