Using UILongPressGestureRecognizer For Subviews of UIScrollview

后端 未结 5 1865

For the past four hours, I have tried many Stack Overlow solutions but none have helped solve my problem.

Here it is,

  • I have a UIScrollView
5条回答
  •  离开以前
    2020-12-21 08:09

    your code seems to be fine,it should work i think.i used below code and its working fine for me.

    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
    longPress.delegate = (id)self;
    longPress.minimumPressDuration=0.05;
    imageView.userInteractionEnabled = YES;
    [imageView addGestureRecognizer:longPress];
    

    and its method,

    - (IBAction)handleLongPress:(UILongPressGestureRecognizer *)sender {
       NSLog(@"detected");
    
    if (sender.state == UIGestureRecognizerStateEnded){
         UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"YES"    delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
         [alert show];
       } 
    }
    

    Here i took imageView as subview of scrollview as u said

提交回复
热议问题