将图像作为子视图添加到另一个图像UIImageView
时,我在新图像上添加了一个标记,该图像在编辑时应遵循(移动、放大/缩小、旋转)。
我无法让品牌保持连接到新图像的框架。 它最初在添加图像时连接,但一旦移动,标记就会离开图像框架。
这是我的代码:
**viewDidLoad:**
if (!_marque)
{
_marque = [[CAShapeLayer layer] retain];
_marque.fillColor = [[UIColor clearColor] CGColor];
_marque.strokeColor = [[UIColor cyanColor] CGColor];
_marque.lineWidth = 1.0f;
_marque.lineJoin = kCALineJoinRound;
_marque.lineDashPattern = [NSArray arrayWithObjects:[NSNumber numberWithInt:10],[NSNumber numberWithInt:5], nil];
_marque.bounds = CGRectMake(_stampedImageView.frame.origin.x, _stampedImageView.frame.origin.y, 0, 0);
_marque.position = CGPointMake(_stampedImageView.frame.origin.x + self.view.frame.origin.x, _stampedImageView.frame.origin.y + self.view.frame.origin.y);
}
[[_stampedImageView layer] addSublayer:_marque];
**marque Method:**
if (![_marque actionForKey:@"linePhase"])
{
CABasicAnimation *dashAnimation;
dashAnimation = [CABasicAnimation animationWithKeyPath:@"lineDashPhase"];
[dashAnimation setFromValue:[NSNumber numberWithFloat:0.0f]];
[dashAnimation setToValue:[NSNumber numberWithFloat:15.0f]];
[dashAnimation setDuration:0.5f];
[dashAnimation setRepeatCount:HUGE_VALF];
[_marque addAnimation:dashAnimation forKey:@"linePhase"];
}
_marque.bounds = CGRectMake(_stampedImageView.frame.origin.x, _stampedImageView.frame.origin.y, 0, 0);
_marque.position = CGPointMake(_stampedImageView.frame.origin.x, _stampedImageView.frame.origin.y);
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddRect(path, NULL, frame);
[_marque setPath:path];
CGPathRelease(path);
_marque.hidden = NO;
**panGestureRecognizer:**
CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:self.view];
if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan)
{
_firstX = [_stampedImageView center].x;
_firstY = [_stampedImageView center].y;
}
translatedPoint = CGPointMake(_firstX+translatedPoint.x, _firstY+translatedPoint.y);
[_stampedImageView setCenter:translatedPoint];
[self showOverlayWithFrame:_stampedImageView.frame];
有人可以帮我看看我错过了什么吗?
谢谢!