长按手势实现


//创建手势
UILongPressGestureRecognizer *longGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];

//将创建好的手势添加到你的控件上
[view addGestureRecognizer:longGesture];

//添加事件
-(void)longPress:(UIGestureRecognizer *)gr
{
   
//确保长按只执行一次
  
if (gr.state==UIGestureRecognizerStateBegan) {
       
NSLog(@"long press ");
 }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章