Touch and drag a UIButton around, but don't trigger it when releasing the finger

前端 未结 3 1733
悲&欢浪女
悲&欢浪女 2021-02-10 17:55

I\'m trying to allow some UIButton instances on one of my views to be touched and dragged around the screen (eventually with momentum, but that\'s for later!). I ha

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-10 18:49

    Use UIControlEventTouchDragInside and UIControlEventTouchUpInside events of UIButton like

    // add drag listener
    [button addTarget:self action:@selector(wasDragged:withEvent:) forControlEvents:UIControlEventTouchDragInside];
    // add tap listener
    [button addTarget:self action:@selector(wasTapped:) forControlEvents:UIControlEventTouchUpInside];
    

    You can use HBDraggableButton control..

提交回复
热议问题