問題は...
パスがあり、それを描画するビューを作成します。ビューは同じ次元のパスを持っています。次に、 sizeThatFit: メソッドをオーバーライドする 2 番目のビューを作成して、2 番目のビューのすべてのスペースがいっぱいになるまで最初のビューがスケーリングされるようにします (sizeThatFit: メソッドが何をするかについての私の考えです!それが正しいかどうかはわかりません)。それがコードです:
CGRect rect = CGPathGetBoundingBox(objPath);
CGRect areaPath = CGRectMake(x, y, rect.size.width, rect.size.height);
FirstView* first = [[FirstView alloc] initWithFrame:areaPath andObjPath:objPath];
SecondView* second = [[SecondView alloc] initWithFrame:CGRectMake(x, y, 200, 200)];
[second addSubview:first];
SecondView では、 sizeThatFit: メソッドをオーバーライドしました!
なぜうまくいかないのかわからない!パスは常に同じ次元です。私は道を取り、道が彼の次元を取るビューでそれを描きます. したがって、たとえば、パスのboundingBoxが[10,10]でビューが[100,100]の場合、そのパスはビューの次元と同じ大きさになります。どのようにできるのか ??
問題が十分に明確であることを願っています。私の英語でごめんなさい:)
これは FirstView.m です。
@synthesize objPath;
- (id)initWithFrame:(CGRect)frame andObjPath:(CGMutablePathRef)path {
self = [super initWithFrame:frame];
if (self) {
// Initialization code.
objPath = CGPathCreateMutable();
CGRect rect = CGPathGetBoundingBox(path);
CGAffineTransform trans = CGAffineTransformMake(10, 0, 0, 10, self.bounds.size.width, self.bounds.size.height);
CGPathAddPath(objPath, &trans, path);
CGRect pathContainer = CGPathGetBoundingBox(path);
CGPathAddRect(objPath, &trans, pathContainer);
CGPathCloseSubpath(objPath);
}
return self;
}
- (void)drawRect:(CGRect)rect {
// Drawing code.
CGContextRef current = UIGraphicsGetCurrentContext();
CGContextAddPath(current, objPath);
CGContextSetLineWidth(current, 0.6);
CGContextSetRGBStrokeColor(current, 0xff / 255.0, 0x40 / 255.0, 0x40 / 255.0, 1);
CGContextSetRGBFillColor(current, 0xff / 255.0, 0xc1 / 255.0, 0xc1 / 255.0, 1);
CGContextDrawPath(current, kCGPathFillStroke);
}
編集:
私が行った場合
FirstView* first = [[FirstView alloc] initWithFrame:areaPath andObjPath:objPath];
SecondView* second = [[SecondView alloc] initWithFrame:CGRectMake(x, y, 200, 200)];
[second addSubview:first];
[first sizeToFit];
SecondView.mi オーバーライド sizeThatFit メソッドでは、最初のビューが適合されます!!! 問題は、パスも適合していないことです!!! それは常に同じ次元を持っています:(
EDIT2
私もこの方法で試しました:
FirstView* first = [[FirstView alloc] initWithFrame:areaPath andObjPath: objPath];
[first setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[first setContentMode:UIViewContentModeScaleAspectFit];
SecondView* second = [[SecondView alloc] initWithFrame:CGRectMake(x, y, 200, 200)];
second.autoresizesSubviews = YES;
[second setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[second setContentMode:UIViewContentModeCenter];
[second addSubview:first];
しかし、何も!すごいストレスです(´;ω;`)
Pls 私は助けが必要です!