長按手勢實現


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

//將創建好的手勢添加到你的控件上
[view addGestureRecognizer:longGesture];

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