Objective-C ++中的UIGestureRecognizer

达姆比尔·辛格(Dharmbir singh)

我想知道UIGestureRecognizer在Objective-C ++中工作与否,因为我已经实现了这一功能,但是却从不调用tap方法。因此,请让我知道在Objective-C ++中是否可能。

        - (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];
    imgView.image = [UIImage imageNamed:@"dharm"];
    [self.view addSubview:imgView];
    imgView.backgroundColor = [UIColor redColor];

    UITapGestureRecognizer* tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
    tapRecognizer.numberOfTapsRequired = 1;
    [tapRecognizer setDelegate:self];
    [imgView addGestureRecognizer:tapRecognizer];
}    
    - (void)tap:(id)sender {
        NSLog(@"Tap Pressed");
    }
Ryancrunchi

尝试添加 [imgView setUserInteractionEnabled:YES];

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章