IOS 單擊手勢(shì)的添加實(shí)現(xiàn)代碼
IOS 單擊手勢(shì)的添加實(shí)現(xiàn)代碼
一,效果圖。
二,工程圖。
三,代碼。
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=@"單擊手勢(shì)的添加"; UIView *parentView=[[UIView alloc]initWithFrame:CGRectMake(50, 100, 200, 200)]; parentView.backgroundColor=[UIColor redColor]; [self.view addSubview:parentView]; //單擊的手勢(shì) 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(@"---單擊手勢(shì)-------"); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. }
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
相關(guān)文章
使用Swift代碼實(shí)現(xiàn)iOS手勢(shì)解鎖、指紋解鎖實(shí)例詳解
這篇文章主要介紹了使用Swift代碼實(shí)現(xiàn)iOS手勢(shì)解鎖、指紋解鎖的實(shí)現(xiàn)過程,非常不錯(cuò)具有參考借鑒價(jià)值,感興趣的朋友一起看看吧2016-06-06iOS 使用 socket 實(shí)現(xiàn)即時(shí)通信示例(非第三方庫)
這篇文章主要介紹了iOS 使用 socket 即時(shí)通信示例(非第三方庫)的資料,這里整理了詳細(xì)的代碼,有需要的小伙伴可以參考下。2017-02-02iOS簡(jiǎn)單易用的GCD計(jì)時(shí)器的實(shí)現(xiàn)原理
在日常開發(fā)中總會(huì)碰到需要計(jì)時(shí)器的功能,常見的定時(shí)器有NSTimer、GCD、CADisplayLink。網(wǎng)上也有很多的教程介紹三者的區(qū)別,今天主要講的是GCD這種方式使用以及封裝。感興趣的小伙伴們可以參考一下2018-11-11iOS通過Runtime實(shí)現(xiàn)友盟統(tǒng)計(jì)的實(shí)例代碼
本篇文章主要介紹了iOS通過Runtime實(shí)現(xiàn)友盟統(tǒng)計(jì)的實(shí)例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-06-06iOS9 系統(tǒng)分享調(diào)用之UIActivityViewController
UIActivityViewController類是一個(gè)標(biāo)準(zhǔn)的view controller,通個(gè)使用這個(gè)controller,你的應(yīng)用程序就可以提供各種服務(wù)。本文給大家介紹iOS9 系統(tǒng)分享調(diào)用之UIActivityViewController,感興趣的朋友一起學(xué)習(xí)吧2015-11-11iOS runtime forwardInvocation詳解及整理
這篇文章主要介紹了 iOS runtime forwardInvocation詳解及整理的相關(guān)資料,需要的朋友可以參考下2017-02-02iOS11 WKWebView 無法加載內(nèi)容的解決方法
這篇文章主要介紹了iOS11 WKWebView 無法加載內(nèi)容,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-11-11