在Scaled CALayer周围安装视图框架

时间:2012-12-18 21:12:44

标签: iphone ios cocoa-touch core-animation calayer

在下面的方法中,我只是通过使用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;

1 个答案:

答案 0 :(得分:1)

我必须这样做,所以我的视图层也有它的anchorPoint和位置设置以匹配我的CAShapeLayers然后它工作:

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