縱觀蘋果的文檔倒是例如,有以下方法:錨定點的CALayer
// 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;
}
}
第一個問題,有人可以解釋設置在子視圖的定位點,並改變中心的邏輯superview(就像爲什麼這樣做了)?
最後,數學如何爲anchorPoint語句工作?如果你有一個界限爲500,500的視圖,並且說你用一個手指觸摸100,100,用另一個手指觸摸500,500。在此框中,您的正常錨點是(250,250)。現在呢? (沒有線索)
謝謝!
@水晶做了這個幫助嗎? – 2011-06-19 18:04:46