IOS如何实现单击手势-成都快上网建站

IOS如何实现单击手势

这篇文章将为大家详细讲解有关IOS如何实现单击手势,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

创新互联主要从事成都做网站、网站建设、外贸营销网站建设、网页设计、企业做网站、公司建网站等业务。立足成都服务灯塔,十年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:13518219792

IOS 单击手势的添加实现代码

一,效果图。

IOS如何实现单击手势

二,工程图。

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如何实现单击手势
网页网址:http://kswjz.com/article/jsgich.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流