2015-04-23 80 views
0

我想知道UIGestureRecognizer是否在Objective-C++中工作,因为我已经实现了这一个,但是分支方法从不调用。所以请让我知道在Objective-C++中是否可能。UIGestureRecognizer in 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"); 
    } 

回答

1

尝试增加[imgView setUserInteractionEnabled:YES];

+0

谢谢@ryancrunchi –