【问题标题】:UILongPressGestureRecognizer in subview didnot work [duplicate]子视图中的 UILongPressGestureRecognizer 不起作用[重复]
【发布时间】:2013-11-02 02:21:52
【问题描述】:
- (void)viewDidLoad
{
    [super viewDidLoad];
    CGRect imageRect = (CGRect){105, 180, 110, 110};
    UIImage *image = [UIImage imageNamed: @"sasuke.png"];
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:imageRect];
    [imageView setImage: image];
    UILongPressGestureRecognizer *longGnizer=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longGo:)];
    imageView.userInteractionEnabled = YES;
    [imageView addGestureRecognizer:longGnizer];
    [self.view addSubview:imageView];
}

- (void)longGo:(UILongPressGestureRecognizer *)aGer{
    if(aGer.state==UIGestureRecognizerStateBegan) {
       NSLog(@"%s",__func__);
    }
}

这是代码,但是 func longGo 从来没有工作过,为什么?当我使用 [self.view addGestureRecognizer:longGnizer] 时,它确实有效。

【问题讨论】:

  • 设置UIImageView的userInteraction为YES

标签: ios objective-c long-press


【解决方案1】:

UIImageViews 默认将userInteractionEnabled 设置为NO。你必须设置imageView.userInteractionEnabled = YES;

【讨论】:

  • 现在我加了,好像不行
  • 是的,你是对的,现在只是对它的另一个控制,所以我无法触摸它,我改变了它的位置,确实有效。thk u
  • 完全正确的答案
猜你喜欢
  • 1970-01-01
  • 2015-12-06
  • 2013-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-02
相关资源
最近更新 更多