我正在尝试为图像(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);