Ios addSubview重置锚点
我正在使用apple示例方法执行平移和挤压,以保持手指挤压处的缩放。代码将移动手指接触的层定位点。一切正常,但当我添加子视图时,锚点会重置,所有内容都不合适。 我试图更改子视图定位点以匹配superview定位点,但它返回到默认定位点 夹持和锚定点调整的代码示例:Ios addSubview重置锚点,ios,objective-c,uiview,ios8,uigesturerecognizer,Ios,Objective C,Uiview,Ios8,Uigesturerecognizer,我正在使用apple示例方法执行平移和挤压,以保持手指挤压处的缩放。代码将移动手指接触的层定位点。一切正常,但当我添加子视图时,锚点会重置,所有内容都不合适。 我试图更改子视图定位点以匹配superview定位点,但它返回到默认定位点 夹持和锚定点调整的代码示例: /** Scale and rotation transforms are applied relative to the layer's anchor point this method moves a gesture recogn
/**
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;
}
}
/**
Scale the piece by the current scale.
Reset the gesture recognizer's rotation to 0 after applying so the next callback
is a delta from the current scale.
*/
- (IBAction)scalePiece:(UIPinchGestureRecognizer *)gestureRecognizer
{
[self adjustAnchorPointForGestureRecognizer:gestureRecognizer];
if ([gestureRecognizer state] == UIGestureRecognizerStateBegan || [gestureRecognizer state] == UIGestureRecognizerStateChanged) {
[gestureRecognizer view].transform = CGAffineTransformScale([[gestureRecognizer view] transform], [gestureRecognizer scale],[gestureRecognizer scale]);
[gestureRecognizer setScale:1];
}
}
我有一个self.canvasView和一个self.workingView。手势在self.canvasView中,self.workingView是self.canvasView的子视图
一切正常,但是每次我向self.workingView添加子视图时,锚定点都会重置,并且一切都不正常
我怎样才能避免这种行为?我在文档中找不到addSubview重置主播点的信息,所以我假设我在这里做了一些错误的事情