美文网首页
字符串给UILongPressGestureRecognizer

字符串给UILongPressGestureRecognizer

作者: 哪有猫不吃鱼 | 来源:发表于2021-12-11 17:52 被阅读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];

相关文章

网友评论

      本文标题:字符串给UILongPressGestureRecognizer

      本文链接:https://www.haomeiwen.com/subject/rtakfrtx.html