UIImageView& CGAffineTransformScale,走错路径

时间:2013-08-06 19:41:29

标签: ios xcode uiimage transform scale

我试图为图像添加边框(UIImageView),除了一件事情之外,一切正常:当我调整图像大小时,我的形状变大(或变小)。这是一些代码:

 CGPoint center = view.center; // view is a UIImageView
 CGAffineTransform transform = CGAffineTransformIdentity;
 CGFloat angle = [(NSNumber *)[view valueForKeyPath:@"layer.transform.rotation.z"] floatValue];
 CGFloat scale = [(NSNumber *)[view valueForKeyPath:@"layer.transform.scale"] floatValue];
 transform = CGAffineTransformTranslate(transform, center.x, center.y);
 transform = CGAffineTransformScale(transform, scale, scale);
 transform = CGAffineTransformRotate(transform, angle);
 transform = CGAffineTransformTranslate(transform, -center.x, -center.y);
 CGPathRef path = CGPathCreateWithRect(view.frame, &transform); // looks like the problem is here
 shape.path = path; // shape is a CAShapeLayer
 CGPathRelease(path);

1 个答案:

答案 0 :(得分:0)

替换

解决
CGPathRef path = CGPathCreateWithRect(view.frame, &transform); 

CGPathAddLines(path, nil, points, 5);