扫码关注官方订阅号
有个需求需要判断使用者是否有手指放在屏幕上。貌似没有这样的方法。
认证0级讲师
判断当前 runloop时候处于tracking mode,如果是,就代表有手指在触碰屏幕
重写Touches的几个方法,Begin开始,End结束
(void)touchesBegan:(NSSet<UITouch > )touches withEvent:(UIEvent *)event{
}
-(void)touchesEnded:(NSSet<UITouch > )touches withEvent:(UIEvent *)event {
-(void)touchesMoved:(NSSet<UITouch > )touches withEvent:(UIEvent *)event {
不知道题主是不是说的这个
在 AppDelegate.m 里面添加下面的方法
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { NSLog(@"开始触摸"); } -(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { NSLog(@"结束触摸"); }
Swift写法如果是全局的话添加到AppDelegate.swift如果是某个视图的话添加到对应的ViewController.swift
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { print("开始触摸") } override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) { print("结束触摸") }
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
判断当前 runloop时候处于tracking mode,如果是,就代表有手指在触碰屏幕
重写Touches的几个方法,Begin开始,End结束
(void)touchesBegan:(NSSet<UITouch > )touches withEvent:(UIEvent *)event{
}
-(void)touchesEnded:(NSSet<UITouch > )touches withEvent:(UIEvent *)event {
}
-(void)touchesMoved:(NSSet<UITouch > )touches withEvent:(UIEvent *)event {
}
不知道题主是不是说的这个
在 AppDelegate.m 里面添加下面的方法
Swift写法
如果是全局的话添加到AppDelegate.swift
如果是某个视图的话添加到对应的ViewController.swift