0

When testing in iPad, I can successfully call the method attached to UILongPressGestureRecognizer in UILabel.

After I have archived the application for Enterprise deployment, UILongPressGestureRecognizer does not work anymore.

I have already added the following codes aside from manually ticking User Interaction Enabled:

In .h file:

@interface BGMSetMenuViewController : UIViewController <UIGestureRecognizerDelegate>

In .m file:

- (void)viewDidLoad
{
    [super viewDidLoad];

    itemPriceLabel.userInteractionEnabled = YES;
    itemNameLabel.userInteractionEnabled = YES;

    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressSetMenuPrice:)];
    longPress.delegate = self;
    [itemPriceLabel addGestureRecognizer:longPress];
}

#pragma mark - UILongPressGestureRecognizerDelegate

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
  return YES;
}

- (void)longPressSetMenuPrice:(UILongPressGestureRecognizer*)gesture
{
  if (gesture.state == UIGestureRecognizerStateEnded) {

    BGMPasscodeViewController *passcodeVC = [[BGMPasscodeViewController alloc] initWithNibName:@"BGMPasscodeViewController" bundle:nil];
    self.providesPresentationContextTransitionStyle = YES;
    self.definesPresentationContext = YES;
    [passcodeVC setModalPresentationStyle:UIModalPresentationOverCurrentContext];
    [self presentViewController:passcodeVC animated:YES completion:nil];

  }
}

Anybody here who have the same experience?

Please note that this was working in Xcode 7 and iOS 9.

Now, I'm using Xcode 8 and testing in iOS 10.0.2 and it doesn't work anymore.

Lie-An
  • 2,563
  • 3
  • 17
  • 20

1 Answers1

0

Try below code:set YES to label userIntractionEnabled also in storyboard

- (void)viewDidLoad {
[super viewDidLoad];
labelTouch.userInteractionEnabled = YES;
[self labelLongPressed:labelTouch];}


- (void)labelLongPressed:(UILabel *)label{
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
                                     initWithTarget:self action:@selector(handleLongPress:)];
longPress.minimumPressDuration = 2; //seconds
longPress.delegate = self;
[label addGestureRecognizer:longPress];}

-(void) handleLongPress : (UITapGestureRecognizer *)sender{
  UIButton *button = (UIButton *)sender.view;
   NSLog(@"longpress");}
G.Anushiya
  • 31
  • 5