2014-12-04 101 views
1

這個問題涉及到項目:https://github.com/FindForm/FFAngularPointilism如何調整superview大小時調整所有子視圖/子圖層?

目前,所有的行爲都是由原始UIImage的尺寸決定的。儘管調整大小,縮小和旋轉,「雙三角形」的繪製仍然保持不變。無論應用的UIImageView的邊界如何,三角模糊都不會改變。

在我的UIImageView子類中,我初始化一個UIImage並調用指定的初始化如下:

- (void)loadMatrix 
{ 
num = 12; 

CGFloat width = self.bounds.size.width; 
CGFloat height = self.bounds.size.height; 
CGFloat theBiggestSideLength = MAX(width, height); 

_array = [NSMutableArray array]; 
_array2 = [NSMutableArray array]; 

for(int i = 0; i < theBiggestSideLength; i += num) 
{ 
    [self.array addObject:[NSMutableArray array]]; 
    [self.array2 addObject:[NSMutableArray array]]; 
} 

for(int i = 0; i < self.array.count; i++) 
{ 
    for(int j = 0; j < self.array.count; j++) 
    { 
     [self.array[i] addObject:[self getRGBAsFromImage:self.image 
                atX:j * 2 * num 
                andY:i * 2 * num]]; 

     int xIndex = ((j * 2 * num) - (num/2.0)); 
     int yIndex = ((i * 2 * num) + (num/2.0)); 
     xIndex %= (int)width * 2; 
     yIndex %= (int)width * 2; 
     NSLog(@"%d", xIndex); 

     [self.array2[i] addObject:[self getRGBAsFromImage:self.image 
                 atX:xIndex 
                andY:yIndex]]; 
    } 
} 

_imageGrayscaleView = [[UIImageView alloc] initWithImage:[self convertToGreyscale:self.image]]; 
_finalbwimage = self.imageGrayscaleView.image; 
_imageGrayscaleView.frame = self.bounds; 
[self insertSubview:_imageGrayscaleView atIndex:0]; 

_viewMask = [[UIView alloc] initWithFrame:self.frame]; 

_viewMask.center = CGPointMake(_viewMask.center.x, 
           _viewMask.center.y + _viewMask.frame.size.height/2.0f); 


_shapeLayer = [[CAShapeLayer alloc] init]; 
CGRect maskRect = CGRectZero; 
CGPathRef path = CGPathCreateWithRect(maskRect, NULL); 
_shapeLayer.path = path; 
CGPathRelease(path); 
self.imageGrayscaleView.layer.mask = _shapeLayer; 
} 

爲了繪製這些瓦片,我添加了一個計時器,並調用下面的方法每個區間。 Num和行正在更新預期:

- (void)drawTile 
{ 
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(pixel * num, row * num, num, num)]; 
view.backgroundColor = [self.array[row] objectAtIndex:pixel]; 
[self addSubview:view]; 
[self.ksubviews addObject:view]; 
UIBezierPath *path = [UIBezierPath bezierPath]; 
[path moveToPoint:CGPointMake(view.frame.origin.x , view.frame.origin.y + (view.frame.size.height))]; 
[path addLineToPoint:CGPointMake(view.frame.origin.x , view.frame.origin.y)]; 
[path addLineToPoint:CGPointMake(view.frame.origin.x + view.frame.size.width, view.frame.origin.y + view.frame.size.height)]; 
[path closePath]; 
CAShapeLayer *shapeLayer = [CAShapeLayer layer]; 
shapeLayer.path = path.CGPath; 
shapeLayer.strokeColor = [[UIColor blackColor] CGColor]; 
shapeLayer.fillColor = [((UIColor *)[self.array2[row] objectAtIndex:pixel]) CGColor]; 
shapeLayer.lineWidth = 0; 
[self.layer addSublayer:shapeLayer]; 
[self.ksublayers addObject:shapeLayer]; 
} 

下面是正確的行爲:

enter image description here

當這個圖像是通過筆尖大小,或以編程方式,設定其邊界可動畫的三角形方塊不變。

+0

我什麼都不懂。 – Andy 2014-12-04 18:01:16

+0

你知道如何處理uiview尺寸/旋轉變化嗎? – Jan 2015-01-09 10:45:15

回答

0

您在類中的方法Draw Rect上進行所有子視圖更改,並且每次進行更改時,都會調用superview的方法setNeedDisplay。

我不明白你的問題,但我希望這有助於!

相關問題