我想知道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");
}
尝试添加 [imgView setUserInteractionEnabled:YES];
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句