objective-c – 如何欺骗OS X应用程序认为鼠标是手指?

objective-c – 如何欺骗OS X应用程序认为鼠标是手指?,第1张

概述我正在写一个包含集合视图的Mac应用程序.此应用程序将在大型触摸屏显示器(来自Planar的 55″ EP series)上运行.由于硬件限制,触摸屏不会发送滚动事件(甚至任何多点触控事件).如何欺骗应用程序以使“mousedown drag”与“mousescroll”相同? 我通过继承NSCollectionView并在其中实现我自己的NSPanGestureRecognizer处理程序来实现 我正在写一个包含集合视图的Mac应用程序.此应用程序将在大型触摸屏显示器(来自Planar的 55″ EP series)上运行.由于硬件限制,触摸屏不会发送滚动事件(甚至任何多点触控事件).如何欺骗应用程序以使“mousedown drag”与“mousescroll”相同?

我通过继承NSCollectionVIEw并在其中实现我自己的NSPanGestureRecognizer处理程序来实现它.不幸的是,结果很笨拙并且没有正常OS X滚动的感觉(即,滚动结束时的速度效果,或内容末端的滚动反d).

@implementation UCtouchScrollCollectionVIEw...- (IBAction)showGestureForScrollGestureRecognizer:(NSPanGestureRecognizer *)recognizer{    CGPoint location = [recognizer locationInVIEw:self];    if (recognizer.state == NSGestureRecognizerStateBegan) {        touchstartPt = location;        startOrigin = [(NSClipVIEw*)[self supervIEw] documentVisibleRect].origin;    } else if (recognizer.state == NSGestureRecognizerStateEnded) {        /* Some notes here about a future feature: the Scroll Bounce           I don't want to have to reinvent the wheel here,but it           appears I already am. Crud.           1. when the touch ends,get the veLocity in vIEw           2. Using the veLocity and a constant "deceleration" factor,you can determine               a. The time taken to decelerate to 0 veLocity               b. the distance travelled in that time           3. If the final scroll point is out of bounds,update it.           4. set up an animation block to scroll the document to that point. Make sure it uses the proper easing to feel "natural".           5. make sure you retain a pointer or something to that animation so that a touch DURING the animation will cancel it (is this even possible?)        */        [self.scrollDelegate.pointSmoother clearPoints];        refreshDelegateTriggered = NO;    } else  if (recognizer.state == NSGestureRecognizerStateChanged) {        CGfloat dx = 0;        CGfloat dy = (startOrigin.y - self.scrollDelegate.scrollScaling * (location.y - touchstartPt.y));        NSPoint scrollPt = NSMakePoint(dx,dy);        [self.scrollDelegate.pointSmoother addPoint:scrollPt];        NSPoint smoothedPoint = [self.scrollDelegate.pointSmoother getSmoothedPoint];        [self scrollPoint:smoothedPoint];        CGfloat end = self.frame.size.height - self.supervIEw.frame.size.height;        CGfloat threshold = self.supervIEw.frame.size.height * kUcpullToRefreshScreenFactor;        if (smoothedPoint.y + threshold >= end &&            !refreshDelegateTriggered) {            NSLog(@"trigger pull to refresh");            refreshDelegateTriggered = YES;            [self.refreshDelegate scrollVIEwReachedBottom:self];        }    }}

关于此实现的说明:我将scrollScaling和pointSmoother放在一起,以尝试改进滚动UX.我使用的触摸屏是基于红外线的,并且非常紧张(特别是当太阳出来时).

如果它是相关的:我在Yosemite beta(14A329r)上使用Xcode 6 beta 6(6A280e),我的构建目标是10.10.

谢谢!

解决方法 我设法使用NSPanGestureRecognizer并模拟了track-pad滚轮事件取得了一些成功.如果你很好地模拟它们,你将获得NSScrollVIEw’免费’的反d.

我没有公共代码,但是我发现的最好的资源解释了NSScrollVIEw期望的是在下面的模拟动量滚动的单元测试中. (请参阅此处的mouseScrollByWithWheelAndMomentumPhases).

https://github.com/WebKit/webkit/blob/master/LayoutTests/fast/scrolling/latching/scroll-iframe-in-overflow.html

mouseScrollByWithWheelAndMomentumPhases的实现提供了有关如何在低级别合成滚动事件的一些提示.我发现我需要的一个补充是在事件中实际设置一个递增时间戳,以便让滚动视图播放球.

https://github.com/WebKit/webkit/blob/master/Tools/WebKitTestRunner/mac/EventSenderProxy.mm

最后,为了实际创建衰减速度,我使用了POPDecayAnimation并调整了NSPanGestureRecognizer的速度以使其感觉相似.它不完美但它确实坚持NSScrollVIEw的反d.

总结

以上是内存溢出为你收集整理的objective-c – 如何欺骗OS X应用程序认为鼠标是手指?全部内容,希望文章能够帮你解决objective-c – 如何欺骗OS X应用程序认为鼠标是手指?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1023099.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存