0

在 iPad 中测试时,我可以成功调用UILongPressGestureRecognizerUILabel 中附加的方法。

在我为企业部署归档应用程序后,UILongPressGestureRecognizer 不再工作。

除了手动打勾外,我已经添加了以下代码User Interaction Enabled:

在 .h 文件中:

@interface BGMSetMenuViewController : UIViewController <UIGestureRecognizerDelegate>

在 .m 文件中:

- (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];

  }
}

这里有人有同样经历吗?

请注意,这适用于 Xcode 7 和 iOS 9。

现在,我正在使用 Xcode 8 并在 iOS 10.0.2 中进行测试,但它不再工作了。

4

1 回答 1

0

试试下面的代码:在情节提要中设置 YES 以标记 userIntractionEnabled

- (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");}
于 2016-10-24T10:13:31.317 回答