作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
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.
@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
respondsToSelector
, 也。
关于ios 9.2 预测TouchesForTouch : No documentation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35686591/
我是一名优秀的程序员,十分优秀!