Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 即使在macOS应用程序之外也能检测到3个手指的平移手势';永远关闭窗口_Objective C_Swift_Macos_Gesture_Pan - Fatal编程技术网

Objective c 即使在macOS应用程序之外也能检测到3个手指的平移手势';永远关闭窗口

Objective c 即使在macOS应用程序之外也能检测到3个手指的平移手势';永远关闭窗口,objective-c,swift,macos,gesture,pan,Objective C,Swift,Macos,Gesture,Pan,我怎样才能在屏幕上的任何地方(不仅仅是在我的应用程序窗口中)永远(而不是在我的应用程序窗口中)检测到mac trackpad上的3个手指平移手势 谢谢 您可以使用GlobalMonitorForEvents- 安装一个事件监视器,该监视器接收发布到的事件的副本 其他应用程序。事件以异步方式传递到您的应用程序 你只能观察这件事 并在回叫中添加一个计数器,用于计算按下的次数。“三个手指以共同的方向扫过触摸板表面是一种滑动手势” 您可以使用下面的代码段 -(NSSet *)touchesMatchi

我怎样才能在屏幕上的任何地方(不仅仅是在我的应用程序窗口中)永远(而不是在我的应用程序窗口中)检测到mac trackpad上的3个手指平移手势


谢谢

您可以使用GlobalMonitorForEvents-

安装一个事件监视器,该监视器接收发布到的事件的副本 其他应用程序。事件以异步方式传递到您的应用程序 你只能观察这件事

并在回叫中添加一个计数器,用于计算按下的次数。

“三个手指以共同的方向扫过触摸板表面是一种滑动手势”

您可以使用下面的代码段

-(NSSet *)touchesMatchingPhase:(NSTouchPhase)phase inView:(NSView *)view;
“轨迹板首选项”窗格包括一个滚动手势选项:两个手指移动滚动视图的内容视图。从技术上讲,滚动手势不是特定的手势,而是鼠标事件。与手势不同,滚轮事件(即NSScrollWheel类型的事件)可以同时具有phase属性和momentumPhase属性。momentumPhase属性可帮助您检测动量滚动,在这种情况下,即使用户不再实际滚动,硬件仍会继续发出滚轮事件。魔术鼠标和多点触控触控板等设备可以实现动量滚动


您可以查看更多信息,以允许监视全局事件,从而使您的应用程序成为受信任的应用程序。它在沙盒环境中不起作用,因此在应用商店中也不起作用

 NSDictionary *options = @{(__bridge id) kAXTrustedCheckOptionPrompt : @YES};
 AXIsProcessTrustedWithOptions((__bridge CFDictionaryRef) options);
测试:

BOOL trusted=AXIsProcessTrusted();
NSLog(@“受信任进程:%d”,受信任)


这里有一个全面的。

M5多点触控支持可以解决您的问题

首先安装库并将其添加到项目中:
pod'm5multi-touchsupport'
(或),然后创建如下代码(+
#import
):

输出将是:

"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"
现在我还没有测试它,但理论上它应该可以工作

编辑:

还要获取其他信息:

/** Identifier of touch, persistent/applicable across events. */
@property (assign, readonly) int identifier;

/** Current state of touch. 0 is not touching, anything else is some kind of touching. */
@property (assign, readonly) M5MultitouchTouchState state;

/** Coordinates of touch (each value 0 -> 1, so basically percent of touch surface). */
@property (assign, readonly) float posX, posY;

/** Coordinates of touch (each value 0 -> 1, so basically percent of touch surface). */
@property (assign, readonly) float velX, velY;

/** Minor and major axis of touch. */
@property (assign, readonly) float minorAxis, majorAxis;

/** Angle of touch (angle of finger tip from north). */
@property (assign, readonly) float angle;

/** Size of touch (finger tip surface area touching). */
@property (assign, readonly) float size;
因此:


特别注意事项在OS X v 10.6中,事件监视器只能监视以下事件类型:NSLeftMouseDragged NSRightMouseDragged NSOtherMouseDragged NSLeftMouseUp NSRightMouseUp NSOtherMouseUp NSLeftMouseDown NSRightMouseDown NSOtherMouseDown NSFlagsChanged NSScrollWheel NSTabletPoint NSTabletProximity NSKeyDown(按键重复次数是使用isARepeat属性确定的。)我还没有时间尝试。根据可用的NSEventMask,这似乎是可能的。我会让你知道的。他没有提到他使用了
NSEvent
监视器。另外,文档提到你需要
按键相关事件的特权,而不是触摸或手势。
/** Identifier of touch, persistent/applicable across events. */
@property (assign, readonly) int identifier;

/** Current state of touch. 0 is not touching, anything else is some kind of touching. */
@property (assign, readonly) M5MultitouchTouchState state;

/** Coordinates of touch (each value 0 -> 1, so basically percent of touch surface). */
@property (assign, readonly) float posX, posY;

/** Coordinates of touch (each value 0 -> 1, so basically percent of touch surface). */
@property (assign, readonly) float velX, velY;

/** Minor and major axis of touch. */
@property (assign, readonly) float minorAxis, majorAxis;

/** Angle of touch (angle of finger tip from north). */
@property (assign, readonly) float angle;

/** Size of touch (finger tip surface area touching). */
@property (assign, readonly) float size;
NSLog(event.size); // Get size
NSLog(event.angle); // Get angle
NSLog(event.state); // Get state (4 = touching)
NSLog(event.posX); // get position x or y