2

在下面的方法中,我只是CAShapeLayers通过使用CATransform3DMakeScale. 我能够正确放大形状图层,但是很难让视图框架放大并适合形状图层生成的图形,就像它应该的那样。一切都是相同的大小,即视图框架与所有形状层的大小相同。

有人对如何解决这个问题有任何建议吗?我尝试更改视图转换属性以及视图层转换属性。不知道我在这里缺少什么。

- (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;
4

1 回答 1

1

我必须这样做,所以我的视图层也设置了锚点和位置以匹配我的 CAShapeLayers,然后它就起作用了:

self.layer.anchorPoint = CGPointMake(0, 0);
self.layer.position = CGPointMake(0, 0);
于 2012-12-25T19:14:37.763 回答