小编One*_*ble的帖子

子视图中的UILongPressGestureRecognizer无法正常工作

- (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__);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是代码,但是func longGo永远不会工作,为什么?当我使用[self.view addGestureRecognizer:longGnizer]时,它确实有效.

objective-c ios long-press

-4
推荐指数
1
解决办法
529
查看次数

标签 统计

ios ×1

long-press ×1

objective-c ×1