最簡單的方法是更改每個弧視圖圖層的錨點。 You can read about the anchor point here如果你還不知道。 您需要將QuartzCore框架添加到您的構建目標並添加#import <QuartzCore/QuartzCore.h>
。
CGRect circleBounds = circleView.bounds;
topArcView.layer.anchorPoint = CGPointMake(.5, 0);
topArcView.layer.position = CGPointMake(CGRectGetMidX(circleBounds), 0);
bottomArcView.layer.anchorPoint = CGPointMake(.5, 1);
bottomArcView.layer.position = CGPointMake(CGRectGetMidX(circleBounds), CGRectGetMaxY(circleBounds));
leftArcView.layer.anchorPoint = CGPointMake(0, .5);
leftArcView.layer.position = CGPointMake(circleBounds.origin.x, CGRectGetMidY(circleBounds));
rightArcView.layer.anchorPoint = CGPointMake(1, .5);
rightArcView.layer.position = CGPointMake(CGRectGetMaxX(circleBounds), CGRectGetMidY(circleBounds));
並非如此,每一個綠色的子視圖都必須是這個圓圈的子視圖。我必須計算應該放置這些弧線的半徑,但是如何計算綠線和淺灰色「輪子」之間的空間長度, – wczekalski 2012-01-04 20:40:36