轻松且线程/内存安全地消费全局 OS X 多点触摸(触摸板、Magic Mouse)事件。
注意:需要 ARC,且 Mac OS 10.8+。
M5MultitouchSupport/M5MultitouchSupport.xcodeproj
项目,并构建默认目标。Products/M5MultitouchSupport.framework
添加到您的项目中。M5MultitouchSupport/M5MultitouchSupport
文件夹拖入您的项目。在您的应用或框架中使用 M5MultitouchSupport
如此简单...
#import <M5MultitouchSupport.h>
[M5MultitouchManager.sharedManager addListenerWithCallback:^(M5MultitouchEvent *event) {
NSLog(event.description);
/*
Touches: (
"ID: 3, State: 4 (Touching), Position: [0.251363, 0.475246], Velocity: [0.009912, -0.003619], Minor Axis: 8.160000, Major Axis: 9.920000, Angle: 1.911052, Size: 0.750000",
"ID: 6, State: 4 (Touching), Position: [0.618595, 0.839751], Velocity: [-0.007434, -0.014476], Minor Axis: 8.230000, Major Axis: 9.220000, Angle: 1.570796, Size: 0.625000",
"ID: 8, State: 4 (Touching), Position: [0.410051, 0.792415], Velocity: [0.008673, 0.018095], Minor Axis: 7.660000, Major Axis: 8.890000, Angle: 1.570796, Size: 0.628906"
), Device ID: 25381376, Frame ID: 1435, Timestamp: 3827.383000
*/
}];
注意:多点触控事件处理在一个单独的线程上完成,但您的监听器将在它被创建的线程上传递事件(或者在原始线程停止时是主线程)。
[M5MultitouchManager.sharedManager addListenerWithTarget:self
selector:@selector(handleMultitouchEvent:)];
- (void)handleMultitouchEvent:(M5MultitouchEvent *)event {
NSLog(event.description);
}
注意:仅保持对目标的弱引用,如果该引用为零,则 M5MultitouchManager
会安全地删除监听器。
M5MultitouchListener *listener = [M5MultitouchManager.sharedManager addListenerWith...
listener.listening = NO;
//Listener will stop receiving events until set to YES
[M5MultitouchManager.sharedManager removeListener:listener];
//Will stop/remove the listener altogether
如果您有功能请求或错误报告,请通过发送拉取请求或在 创建新问题 的方式来帮助。
由 Mathew Huusko V 和 项目贡献者 提供 M5MultitouchSupport
。如果您在项目中使用了 M5MultitouchSupport
,将非常感谢您提供归属。