手势

本文详细介绍了iOS中常见的手势识别器,包括轻拍、轻扫、捏合、旋转和平移等,并提供了具体的实现代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

手势
addGestureRecognizer:给视图添加手势,然后再实现@selector( )里的方法 

    轻拍(tap)

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];

    //设置轻拍次数(默认1)(按2次好使)

    tap.numberOfTapsRequired = 2;

    //设置轻拍的手指个数(默认1)

 // tap.numberOfTouchesRequired = 2;

    轻扫(swipe)

    //默认从左往右

    UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipe:)];

    [imageView addGestureRecognizer:swipe];

    //要么上下一起 要么左右一起(下面的写法只能执行左右)

    swipe.direction = UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionUp;

    //设置轻扫手指个数

    swipe.numberOfTouchesRequired = 2;

    捏合(pinch

    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinch:)];

    [imageView addGestureRecognizer:pinch];

    旋转 (Rotation)

    UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotation:)];

    [imageView addGestureRecognizer:rotation];

     平移(Pan)

    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];

    [imageView addGestureRecognizer:pan];

   长按(LongPress)

    UILongPressGestureRecognizer *longpress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longpress:)];

    [imageView addGestureRecognizer:longpress];

    //长按时间

    longpress.minimumPressDuration = 1;


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值