gpt4 book ai didi

ios 9.2 预测TouchesForTouch : No documentation

转载 作者:行者123 更新时间:2023-12-01 20:21:09 25 4
gpt4 key购买 nike

WWDC 2015 - session 233 - iOS:
https://developer.apple.com/videos/play/wwdc2015/233/?time=74

我可以找到 Apple 演示代码,但我终生无法在 [UIEvent predictedTouchesForTouch:] 上找到任何实际文档.

它应该是一个 iOS 9 API。这个 API 是活跃的,只是还没有记录吗?我可以看到他们添加到 Swift 的 API 差异,但仍然没有文档。

最佳答案

是的,预测触摸的文档(很像合并触摸的文档)很少。在这一点上(Xcode 7.2 和 7.3 Beta 4),我看到的唯一引用(除了您引用的 WWDC 视频和其他散布在网络上的演示)在标题中,它描述了预测的接触:

An array of auxiliary UITouch’s for touch events that are predicted to occur for a given main touch. These predictions may not exactly match the real behavior of the touch as it moves, so they should be interpreted as an estimate.



但它的工作原理与您引用的 WWDC 视频中的描述完全相同,包括 Swift 和 Objective-C。

请注意,您可能不会在模拟器上看到预测和合并的触摸,但如果您使用功能强大的设备,您会看到。我在使用我的 iPhone 6+ 时偶尔会看到预期的触摸,但在 iPad Pro 上始终可以看到它们(如果您在 iPad Pro 上使用 Apple Pencil 甚至更多)。

只是为了说明合并和预测的触摸,这里是一个 Objective-C 演示:
@interface ViewController ()

@property (nonatomic, strong) UIBezierPath *path;
@property (nonatomic, weak) CAShapeLayer *pathLayer;
@property (nonatomic, weak) CAShapeLayer *predictedPathLayer;

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];

// set up layer for the main (non-predicted) path; line blue line

CAShapeLayer *mainPathLayer = [CAShapeLayer layer];
mainPathLayer.lineWidth = 1;
mainPathLayer.strokeColor = [UIColor blueColor].CGColor;
mainPathLayer.fillColor = [UIColor clearColor].CGColor;
mainPathLayer.lineCap = kCALineCapRound;
mainPathLayer.lineJoin = kCALineJoinRound;
mainPathLayer.frame = self.view.layer.bounds;
[self.view.layer addSublayer:mainPathLayer];
self.pathLayer = mainPathLayer;

// set up layer for the predicted path, if any; thicker red line (just so I can see it clearly)

CAShapeLayer *predictedPathLayer = [CAShapeLayer layer];
predictedPathLayer.lineWidth = 5;
predictedPathLayer.strokeColor = [UIColor redColor].CGColor;
predictedPathLayer.fillColor = [UIColor clearColor].CGColor;
predictedPathLayer.lineCap = kCALineCapRound;
predictedPathLayer.lineJoin = kCALineJoinRound;
predictedPathLayer.frame = self.view.layer.bounds;
[self.view.layer addSublayer:predictedPathLayer];
self.predictedPathLayer = predictedPathLayer;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
self.path = [UIBezierPath bezierPath];
[self.path moveToPoint:[touch locationInView:self.view]];
}

- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:self.view];

// handle coalesced touches

NSArray<UITouch *> *coalescedTouches = [event coalescedTouchesForTouch:touch];
for (UITouch *coalescedTouch in coalescedTouches) {
location = [coalescedTouch locationInView:self.view];
[self.path addLineToPoint:location];
}

self.pathLayer.path = self.path.CGPath;

// now handle predicted touches

UIBezierPath *predictedPath = [UIBezierPath bezierPath];
[predictedPath moveToPoint:location];
NSArray<UITouch *> *predictedTouches = [event predictedTouchesForTouch:touch];


for (UITouch *predictedTouch in predictedTouches) {
[predictedPath addLineToPoint:[predictedTouch locationInView:self.view]];
}

self.predictedPathLayer.path = predictedPath.CGPath;

// for diagnostic purposes, let's log the count of each; do not do this in production app

NSLog(@"%ld %ld", [coalescedTouches count], [predictedTouches count]);
}

- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
self.predictedPathLayer.path = NULL; // discard any predicted path, because that's no longer valid
}

@end

如果您需要支持 9 之前的 iOS 版本,请查看 respondsToSelector , 也。

Swift 示例非常相似。请参阅这篇关于平滑曲线的无关帖子,它说明了如何在 Swift 中使用预测(和合并)触摸: Drawing class drawing straight lines instead of curved lines

关于ios 9.2 预测TouchesForTouch : No documentation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35686591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com