目标 c 中的合并和预测性触摸 [英] coalesced and predictive touch in objective c
问题描述
我在 Objective C 中有一个庞大的项目(一个应用程序),我想认真地过渡到 iOS 9.应用程序中有很多绘图,我想使用预测和合并触摸.如 http://flexmonkey.blogspot.de/中所述2015/09/advanced-touch-handling-in-ios9.html那里的代码看起来像
I have a huge project (an App) in Objective C and I want to make a serious transition to iOS 9. There is a lot of drawing in the app and I want to use predictive and coalesced touch. As described in http://flexmonkey.blogspot.de/2015/09/advanced-touch-handling-in-ios9.html The code there looks like
if let coalescedTouches = event.coalescedTouchesForTouch(touch)
{
print("coalescedTouches:", coalescedTouches.count)
for coalescedTouch in coalescedTouches
{
let locationInView = coalescedTouch.locationInView(view)
coalescedDrawPath.addLineToPoint(locationInView)
coalescedDrawPath.appendPath(UIBezierPath.createCircleAtPoint(locationInView, radius: 2))
coalescedDrawPath.moveToPoint(locationInView)
}
coalescedDrawLayer.path = coalescedDrawPath.CGPath
}
然而这是斯威夫特.是否有任何直接的方法也可以在目标 C 中使用这些功能.我在网上没有找到任何内容.
However this is Swift. Is there any direct way to use these features also in objective C. I did find nothing on the web.
推荐答案
objective c 中的代码块类似于:
That block of code in objective c is something like:
-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
UIBezierPath *coalescedPath = [[UIBezierPath alloc]init];
[coalescedPath moveToPoint:CGPointZero];
UITouch *touch = [touches anyObject];
if ([event coalescedTouchesForTouch:touch]) {
NSArray *coalescedTouches = [NSArray arrayWithArray: [event coalescedTouchesForTouch:touch]];
NSLog(@"Coalesced Touches: %lu",(unsigned long)[coalescedTouches count]);
for (UITouch*coalescedTouch in coalescedTouches) {
CGPoint locationInView = [coalescedTouch locationInView:self.view];
[coalescedPath addLineToPoint:locationInView];
[coalescedPath appendPath:[UIBezierPath bezierPathWithOvalInRect:CGRectMake(locationInView.x-2.0, locationInView.y-2.0, 4.0, 4.0)]];
[coalescedPath moveToPoint:locationInView];
}
[[UIColor blackColor] setStroke];
[coalescedPath stroke];
}
}
目前,Apple 的所有 API 都是用 Objective C 和 Swift 编写的.查看 UITouch 和 UIEvent 参考指南,了解如何实现预测性和合并式触摸 API.
For the moment of all of Apple's API is being written in both Objective C and Swift. Look at UITouch and UIEvent reference guides on how to implement predictive and coalesced touch API.
这篇关于目标 c 中的合并和预测性触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!