IOS 單擊手勢的添加實現(xiàn)代碼
更新時間:2017年05月16日 11:13:44 作者:小弦事務(wù)所
這篇文章主要介紹了IOS 單擊手勢的添加實現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下
IOS 單擊手勢的添加實現(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=@"單擊手勢的添加"; 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. }
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關(guān)文章
使用Swift代碼實現(xiàn)iOS手勢解鎖、指紋解鎖實例詳解
這篇文章主要介紹了使用Swift代碼實現(xiàn)iOS手勢解鎖、指紋解鎖的實現(xiàn)過程,非常不錯具有參考借鑒價值,感興趣的朋友一起看看吧2016-06-06iOS 使用 socket 實現(xiàn)即時通信示例(非第三方庫)
這篇文章主要介紹了iOS 使用 socket 即時通信示例(非第三方庫)的資料,這里整理了詳細(xì)的代碼,有需要的小伙伴可以參考下。2017-02-02iOS通過Runtime實現(xiàn)友盟統(tǒng)計的實例代碼
本篇文章主要介紹了iOS通過Runtime實現(xiàn)友盟統(tǒng)計的實例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-06-06iOS9 系統(tǒng)分享調(diào)用之UIActivityViewController
UIActivityViewController類是一個標(biāo)準(zhǔn)的view controller,通個使用這個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)容,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-11-11