0

我有来自具有多个触摸手势的框架的第三方视图,我想在顶部添加一个 UILabel 来处理单击事件。出于某种原因,UILabel 上的触摸事件在它是第三方视图的子视图时不起作用,但是当我将视图切换到普通 UIView 时,它会按预期工作。在这里我制作标签:

  CGRect frame = CGRectMake(0, 0, 160, 40);
  UILabel* label = [[UILabel alloc] initWithFrame:frame];
  label.text = [NSString stringWithFormat:@"label"];
  label.userInteractionEnabled = YES;

  UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self
                                      action:@selector(labelTapped:)];
  singleTap.numberOfTapsRequired = 1;
  [label addGestureRecognizer:singleTap];
4

0 回答 0