UIView添加点击事件

来源:互联网 发布:淘宝如何好评截图 编辑:程序博客网 时间:2024/05/19 15:24


使用 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");

  }




0 0
原创粉丝点击