1

这是我的问题,当我使用 UILongPressGestureRecognizer 时,它只在第二次起作用......我按下按钮 3 秒但它不起作用,但我第二次按下按钮 3 秒它工作正常......一些想法?

-(IBAction)seleccionar1:(id)sender{
UILongPressGestureRecognizer *longpressGesture =[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressHandler:)];
longpressGesture.minimumPressDuration = 3;
[longpressGesture setDelegate:self];
[sender addGestureRecognizer:longpressGesture];}

-(IBAction)seleccionar2:(id)sender{
UILongPressGestureRecognizer *longpressGesture =[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressHandler:)];
longpressGesture.minimumPressDuration = 3;
[longpressGesture setDelegate:self];
[sender addGestureRecognizer:longpressGesture];}

- (void)longPressHandler:(UILongPressGestureRecognizer *)gestureRecognizer{
if(gestureRecognizer.view==boton1)
{
    [boton1 setTitle:@"Funciona 1" forState:UIControlStateNormal];
}
if(gestureRecognizer.view==boton2)
{
    [boton2 setTitle:@"Funciona 2" forState:UIControlStateNormal];
}}

感谢所有朋友。

此致

4

1 回答 1

2

因为在第一次没有将手势添加到您将其添加到用户操作的按钮中.. 所以将手势添加到之前的按钮中,例如在 viewDidLoad 中。

于 2012-02-15T19:58:04.940 回答