UILongPressGestureRecognizer的回調(diào)中可以.view來獲取控件
///創(chuàng)建長按手勢
UILongPressGestureRecognizer *longPress=[[UILongPressGestureRecognizer alloc] initWithTarget:self action:sl];
///設置觸發(fā)時間
longPress.minimumPressDuration=1;
///給btn添加手勢
[btnaddGestureRecognizer:longPress];
//長按手勢處理方法
- (void) longPress:(UILongPressGestureRecognizer *)gesture{
//? ? gesture.minimumPressDuration=3;
? ? if (gesture.state==UIGestureRecognizerStateBegan) {
? ? ? ? NSLog(@"長按觸發(fā)tag =%ld", gesture.view.tag);
? ? }
}
////通過字符串創(chuàng)建SEL
?NSString*str = @"longPress:";
?SEL?sl =NSSelectorFromString(str);
UILongPressGestureRecognizer *longPress=[[UILongPressGestureRecognizer alloc] initWithTarget:self action:sl];