这篇文章主要介绍了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.
}
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
沃梦达教程
本文标题为:IOS 单击手势的添加实现代码


基础教程推荐
猜你喜欢
- Android开发Compose集成高德地图实例 2023-06-15
- iOS Crash常规跟踪方法及Bugly集成运用详细介绍 2023-01-18
- Android Compose自定义TextField实现自定义的输入框 2023-05-13
- iOS中如何判断当前网络环境是2G/3G/4G/5G/WiFi 2023-06-18
- Flutter进阶之实现动画效果(三) 2022-10-28
- MVVMLight项目Model View结构及全局视图模型注入器 2023-05-07
- IOS获取系统相册中照片的示例代码 2023-01-03
- iOS开发 全机型适配解决方法 2023-01-14
- iOS开发使用XML解析网络数据 2022-11-12
- Android实现短信验证码输入框 2023-04-29