有个需求需要判断使用者是否有手指放在屏幕上。貌似没有这样的方法。
认证0级讲师
Determine whether the current runloop is in tracking mode. If so, it means a finger is touching the screen
Rewrite several methods of Touches, Begin and 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 {
I don’t know if this is what the questioner is talking about
Add the following method in AppDelegate.m
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { NSLog(@"开始触摸"); } -(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { NSLog(@"结束触摸"); }
Swift writing methodIf it is global, add it to AppDelegate.swiftIf it is a certain view, add it to the corresponding ViewController.swift
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { print("开始触摸") } override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) { print("结束触摸") }
Determine whether the current runloop is in tracking mode. If so, it means a finger is touching the screen
Rewrite several methods of Touches, Begin and 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 {
}
I don’t know if this is what the questioner is talking about
Add the following method in AppDelegate.m
Swift writing method
If it is global, add it to AppDelegate.swift
If it is a certain view, add it to the corresponding ViewController.swift