繁体   English   中英

长按手势上的发送按钮

[英]Send button on Long press gesture

如何长按手势发送按钮名称,标签或文本? 我需要知道长期以来的按钮名称。

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    [button setTagS:[[ToalData objectAtIndex:i] objectAtIndex:4]];
    [button addTarget:self action:@selector(siteButtonPressed:)  forControlEvents:UIControlEventTouchUpInside];

    ///For long//
    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
                                               initWithTarget:self
                                               action:@selector(handleLongPress:)];
    longPress.minimumPressDuration = 1.0;
    [button addGestureRecognizer:longPress];

    ////


    NSString *string1 = [NSString stringWithFormat:@"%@", [[ToalData objectAtIndex:i] objectAtIndex:1]];
    [button setTitle:string1 forState:UIControlStateNormal];
    button.frame = CGRectMake(XLocatioan, YLocation, 90, 30);

    [self.view addSubview:button];


(void)handleLongPress:(UILongPressGestureRecognizer*)sender
{

if (sender.state == UIGestureRecognizerStateEnded)
{
    NSLog(@"UIGestureRecognizerStateEnded");

}
else if (sender.state == UIGestureRecognizerStateBegan){
    NSLog(@"UIGestureRecognizerStateBegan");




       }

}

每个手势识别器都附加到viewview ,该view是手势识别器的属性。

因此,在您的“ handleLongPress ”方法中,您可以执行以下操作:

UIButton *button = (UIButton *)sender.view;

NSLog(@"title is %@", button.titleLabel.text);
NSLog(@"tag is %d", button.tag);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM