【问题标题】:UILongPressGestureRecognizer not working after archiving application归档应用程序后,UILongPressGestureRecognizer 不工作
【发布时间】:2016-10-24 08:24:44
【问题描述】:

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

在我为企业部署归档应用程序后,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 中进行测试,但它不再工作了。

【问题讨论】:

  • 发布一些带有问题的UILongPressGestureRecognizer的代码。
  • @JamshedAlam,我已经添加了一些代码和解释。
  • 你设置 longPress.delegate = self 了吗?
  • @user3182143,是的,我也有它,我也有 UIGestureRecognizerDelegate。
  • 没有看到其他代码,无法给出解决方案。

标签: ios objective-c xcode8 uilongpressgesturerecogni


【解决方案1】:

试试下面的代码:在故事板中设置 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");}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-21
    • 2012-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-27
    相关资源
    最近更新 更多