IOS如何实现单击手势
这篇文章将为大家详细讲解有关IOS如何实现单击手势,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
创新互联主要从事成都做网站、网站建设、外贸营销网站建设、网页设计、企业做网站、公司建网站等业务。立足成都服务灯塔,十年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:13518219792
IOS 单击手势的添加实现代码
一,效果图。
二,工程图。
三,代码。
RootViewController.h
#import@interface RootViewController : UIViewController @end
RootViewController.m
#import "RootViewController.h" @interface RootViewController () @end @implementation RootViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. //添加背景 [self addView]; } #pragma -mark -functions //添加背景 -(void)addView { self.title=@"单击手势的添加"; UIView *parentView=[[UIView alloc]initWithFrame:CGRectMake(50, 100, 200, 200)]; parentView.backgroundColor=[UIColor redColor]; [self.view addSubview:parentView]; //单击的手势 UITapGestureRecognizer *tapRecognize = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTap:)]; tapRecognize.numberOfTapsRequired = 1; tapRecognize.delegate = self; [tapRecognize setEnabled :YES]; [tapRecognize delaysTouchesBegan]; [tapRecognize cancelsTouchesInView]; [self.view addGestureRecognizer:tapRecognize]; } #pragma UIGestureRecognizer Handles -(void) handleTap:(UITapGestureRecognizer *)recognizer { NSLog(@"---单击手势-------"); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. }
关于“IOS如何实现单击手势”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
当前题目:IOS如何实现单击手势
URL链接:http://ybzwz.com/article/jsgich.html