字符串给UILongPressGestureRecognizer

2021-12-11  本文已影响0人  哪有猫不吃鱼

UILongPressGestureRecognizer的回调中可以.view来获取控件

///创建长按手势

UILongPressGestureRecognizer *longPress=[[UILongPressGestureRecognizer alloc] initWithTarget:self action:sl];

///设置触发时间

longPress.minimumPressDuration=1;

///给btn添加手势

[btnaddGestureRecognizer:longPress];

//长按手势处理方法

- (void) longPress:(UILongPressGestureRecognizer *)gesture{

//    gesture.minimumPressDuration=3;

    if (gesture.state==UIGestureRecognizerStateBegan) {

        NSLog(@"长按触发tag =%ld", gesture.view.tag);

    }

}

////通过字符串创建SEL

 NSString*str = @"longPress:";

 SEL sl =NSSelectorFromString(str);

UILongPressGestureRecognizer *longPress=[[UILongPressGestureRecognizer alloc] initWithTarget:self action:sl];

上一篇下一篇

猜你喜欢

热点阅读