【问题标题】:UILongPressGestureRecognizer only call the second timeUILongPressGestureRecognizer 只调用第二次
【发布时间】:2012-02-15 11:27:02
【问题描述】:

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

感谢所有朋友。

最好的问候

【问题讨论】:

    标签: iphone button uipangesturerecognizer


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-20
      • 2012-12-03
      • 1970-01-01
      • 2012-12-10
      相关资源
      最近更新 更多