【发布时间】:2014-07-11 01:46:24
【问题描述】:
我有两个UIView 添加到ViewController 和UITapGestureRecognizer。它们的框架处于冲突状态(假设它们相等以便于理解),当我单击UIView 时,我想为两个视图触发识别器功能,而不仅仅是最后添加为子视图的一个。有什么办法吗?
用于创建 UIView 和手势的代码:
UIView *a = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
UITapGestureRecognizer *aa =
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDeviceClick:)];
[a addGestureRecognizer:aa];
[self.view addSubview:a];
UIView *b = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
UITapGestureRecognizer *bb =
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDeviceClick:)];
[b addGestureRecognizer:bb];
[self.view addSubview:b];
及功能:
-(void)handleDeviceClick:(UITapGestureRecognizer*)recognizer{
NSLog(@"device click occured");
}
UIGestureRecognizerDelegate 被添加到我的头文件中
【问题讨论】:
标签: ios objective-c ipad uiview uitapgesturerecognizer