使用 UITapGestureRecognizer ,创建一个 UITapGestureRecognizer 将它添加到view上即可
事例代码
UIView *tapView=[[UIView alloc]initWithFrame:SCREEN_FRAME]; UITapGestureRecognizer *tapGesturRecognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)]; [tapView addGestureRecognizer:tapGesturRecognizer]; -(void)tapAction:(id)tap { NSLog(@"点击了tapView"); }
标签:
UIView添加点击事件