2012-12-18 21 views
2

在下面的方法中,我只是使用CATransform3DMakeScale來擴大一串CAShapeLayers,它們附加到我的視圖圖層屬性。我能夠正確地放大形狀圖層,但是我很難讓視圖框架放大並適合形狀圖層生成的圖形。一切都是相同的大小,即視圖框架與所有形狀圖層的大小相同。按比例調整視圖框CALayer

任何人有任何建議如何解決這個問題?我試着改變視圖轉換屬性以及視圖圖層轉換屬性。不知道我在這裏錯過了什麼。

- (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; 
+0

它是什麼樣子?目前還不清楚哪些是不起作用的。 – Mundi

+0

@mundi - 稍後我會試着拍一張照片,但是當我放大照片時,它會從框架移到左上方。當我減少它時,情況正好相反。 –

回答

1

我不得不這樣做我的視圖層也有它的anchorPoint和位置設置爲匹配我的CAShapeLayers然後它的工作:

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