将图像作为SubView添加到另一个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];
有人可以帮我看看我错过了什么吗?
谢谢!
答案 0 :(得分:0)
我想你可能会在这一行中出错:
CGPathAddRect(path, NULL, frame);
您还没有在我能看到的任何地方定义框架。也许_stampedImageView.frame?