欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

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

程序员文章站 2023-12-19 18:58:46
ios 单击手势的添加实现代码 一,效果图。 二,工程图。 三,代码。 rootviewcontroller.h #import

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

一,效果图。

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

二,工程图。

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

三,代码。

rootviewcontroller.h

#import <uikit/uikit.h>

@interface rootviewcontroller : uiviewcontroller
<uigesturerecognizerdelegate>

@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.
}

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

上一篇:

下一篇: