从苹果的文档中查看Touches示例,有这个方法:
// scale and rotation transforms are applied relative to the layer's anchor point
// this method moves a gesture recognizer's view's anchor point between the user's fingers
- (void)adjustAnchorPointForGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer {
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
UIView *piece = gestureRecognizer.view;
CGPoint locationInView = [gestureRecognizer locationInView:piece];
CGPoint locationInSuperview = [gestureRecognizer locationInView:piece.superview];
piece.layer.anchorPoint = CGPointMake(locationInView.x / piece.bounds.size.width, locationInView.y / piece.bounds.size.height);
piece.center = locationInSuperview;
}
}
首先问题是,有人能解释一下在子视图中设置锚点并改变父视图的中心的逻辑吗?为什么要这样做?
最后,锚点语句的数学计算是如何工作的?如果您有一个边界为500、500的视图,并用一只手指触摸100、100,另一只手指触摸500、500。在这个框中,您的正常锚点是(250, 250)。现在它是多少?(完全不知道)
谢谢!