[IOS]手势总结

1.UIPanGestureRecognizer 判断向左向右:

https://stackoverflow.com/questions/5187502/how-can-i-capture-which-direction-is-being-panned-using-uipangesturerecognizer

 

 

- (void)handleGesture:(UIPanGestureRecognizer *)gestureRecognizer
{
//获取手势的加速度
    CGPoint velocity = [gestureRecognizer velocityInView:yourView];

    if(velocity.x > 0)
    {
        NSLog(@"gesture went right");
    }
    else
    {
        NSLog(@"gesture went left");
    }
}

 手势的几种状态:

UIGestureRecognizerStateBegan:移动开始

UIGestureRecognizerStateChanged:移动中

UIGestureRecognizerStateEnded:移动结束

 

2.新建单击手势:

声明:

@property (nonatomic, strong) UITapGestureRecognizer *tapGesture;
 方法:

 

 

#pragma mark - tap gesture method
-(UITapGestureRecognizer *)tapGesture{
    if (!_tapGesture) {
        _tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapAction:)];
//单击
        [_tapGesture setNumberOfTapsRequired:1];
        
    }
    return _tapGesture;
}

//触发
- (void)handleTapAction:(UITapGestureRecognizer *)tapGesture{

    [self resetShowType:PSDrawerManagerShowCenter];
    //刷新UI,有时需要异步
    dispatch_async(dispatch_get_main_queue(), ^{
        [self callNotificationReceiver:@"show_center"];
    });
}

-(void)addTapGesture{
    if (!_tapGesture) {
//注意:这里要使用self.tapGesture而不是_tapGesture,要不会报错
        [_cover_view addGestureRecognizer:self.tapGesture];
    }
}

-(void)removeTapGesture{
    if (_tapGesture) {
        [self.centerViewController.view removeGestureRecognizer:_tapGesture];
    }
}
 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值