我想检测一下UIView
&检测哪个UIView
被点击类似于触摸UIButton?你们能解释一下你为什么给出负面标记而不是给出负面标记。我没想到这个问题对我有用
iOS Detect tap down and touch up of a UIView
How to detect touch over a UIView when touched over a UIButton?
我们已按下按钮- (IBAction)Action_Wallet:(id)sender;
我们是否有UIView
答案 0 :(得分:2)
这是一个简单的例子。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
float y=50;
for (int i=1; i<8; i++)
{
UIView *vwDay=[[UIView alloc]init];
[vwDay setFrame:CGRectMake(16, y, 252, 45)];
[vwDay setBackgroundColor:[UIColor brownColor]];
[vwDay setUserInteractionEnabled:YES];
[vwDay setTag:2000+i];
UITapGestureRecognizer *tappedOnDay=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tappedOnDay:)];
[vwDay addGestureRecognizer:tappedOnDay];
[self.view addSubview:vwDay];
y=y+50;
}
}
-(void)tappedOnDay:(UITapGestureRecognizer*)recognizer
{
UIView *vwDay=(UIView*)recognizer.view;
NSLog(@"Tapped on view: %ld",vwDay.tag-2000);
}
在这里,我正在准备7个视图,并为每个视图提供tapGesture&amp;只需打印用户点击的视图编号。