在以下方法中,我只是通过使用CAShapeLayers来放大一堆附加到我的views图层属性的CATransform3DMakeScale。我能够正确地放大形状层,但是很难让视框放大并适合形状层所产生的图形。一切都具有相同的大小,即,视图框与所有形状层的大小都相同。

有人对如何解决此问题有任何建议吗?我尝试过更改views变换属性以及views图层变换属性。不知道我在这里想念的是什么。

- (void) setSize:(CGSize)size
{
    CATransform3D transform = CATransform3DMakeScale(size.width / (self.graphic.initialSize.width), size.height / (self.graphic.initialSize.height), 1);
    self.layer.sublayerTransform = transform;
    self.frame = CGRectMake(0, 0, size.width, size.height);
    self.graphic.size = CGSizeMake(size.width, size.height);
}

还供参考,这是我如何设置视图层:
- (id)initWithGraphic:(Graphic*)graphic
{
    self = [super initWithFrame:CGRectZero];
    if (self)
    {
        self.backgroundColor = [UIColor clearColor];

        _graphic = [graphic retain];

        self.frame = CGRectMake(0,0, _graphic.initialSize.width, _graphic.initialSize.height);
        self.layer.shouldRasterize = YES;

        for (int i = 0; i < [_graphic.shapeLayers count]; i++)
        {
            [self.layer addSublayer:[_graphic.shapeLayers objectAtIndex:i]];
        }
    }
    return self;
}

这是我设置形状层之一的方法:
CAShapeLayer *outlineShapeLayer = [[CAShapeLayer alloc] init];
outlineShapeLayer.anchorPoint = CGPointMake(0, 0);
outlineShapeLayer.fillColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1].CGColor;
outlineShapeLayer.bounds = shapeLayerFrame;
outlineShapeLayer.mutablePath = mutablePath;

最佳答案

我必须这样做,以便我的视图层也设置了anchorPoint和position以匹配我的CAShapeLayers,然后它起作用了:

self.layer.anchorPoint = CGPointMake(0, 0);
self.layer.position = CGPointMake(0, 0);

关于iphone - 在缩放的CALayer周围安装视框,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13941596/

10-08 20:56