UILongPressGestureRecognizer仅第二次调用

时间:2012-02-15 11:27:03

标签: iphone button uipangesturerecognizer

这是我的问题,当我使用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];
}}

感谢所有朋友。

祝你好运

1 个答案:

答案 0 :(得分:2)

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

相关问题