Ce que j'essaie d'accomplir consiste à tracer des lignes courbes à partir du centre d'une vue. Jusqu'à présent, avec l'aide de beaucoup de googling et ce site ... J'ai accompli l'image ci-dessous.Core Graphics AddQuadCureToPoint à partir du centre de la vue/du cercle
http://www.flickr.com/photos/[email protected]/9100635690/
Ce que je voudrais faire est d'avoir courbé des lignes comme l'image suivante ...
http://www.flickr.com/photos/[email protected]/9100634674/
Toute aide serait appréciée. J'ai inclus le code jusqu'à présent.
#import <UIKit/UIKit.h>
@interface ChartView : UIView
@property (nonatomic,assign) int angle;
@end
----------------------------------------------------------------------
#import "ChartView.h"
#import <QuartzCore/QuartzCore.h>
/** Helper Functions **/
#define degree_to_radians(deg) ((M_PI * (deg))/180.0)
#define radians_to_degrees(rad) ((180.0 * (rad))/M_PI)
@interface ChartView(){
int radius;
}
@end
@implementation ChartView
-(id)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if(self){
self.backgroundColor = [UIColor whiteColor];
[self.layer setBorderWidth:1.0];
[self.layer setBorderColor:[UIColor redColor].CGColor];
//Define the circle radius taking into account the safe area
radius = self.frame.size.width/2;
//Initialize the Angle at 0
self.angle = 360;
}
return self;
}
-(void)drawRect:(CGRect)rect{
//Circle center
int numberOfSections = 96; //24 major lines
CGFloat angleSize = 2 * M_PI/numberOfSections;
CGContextRef context = UIGraphicsGetCurrentContext();
//draw the main outside circle
CGRect circleRect = CGRectMake(0.0, 0.0, 720., 720.);
CGContextSetLineWidth(context, .5);
CGContextSetRGBStrokeColor(context, 0.0, 2.0, 4.0, 1.0);
CGContextStrokeEllipseInRect(context, circleRect);
CGPoint centerPoint = CGPointMake(circleRect.size.width/2 , circleRect.size.height/2);
//setup for drawing lines from center, straight lines, need curved lines
CGContextTranslateCTM(context, 0.0, 0.0);
for (int x = 0; x < numberOfSections; x++) {
CGContextSetLineWidth(context, .5);
CGContextSetRGBStrokeColor(context, 0.0, 2.0, 4.0, 1.0);
CGContextMoveToPoint(context, self.frame.size.width/2, self.frame.size.height/2);
CGContextAddLineToPoint(context, centerPoint.x + radius * cos(angleSize * x) ,centerPoint.y + radius * sin(angleSize * x));
CGContextStrokePath(context);
}
CGContextSetLineWidth(context, .5);
CGContextSetRGBStrokeColor(context, 0.0, 2.0, 4.0, 1.0);
CGContextSetRGBFillColor(context, 1., 1., 1., 1.0);
//Taken from Hypnotizer code
float maxRadius = 360.0;
CGContextSetLineWidth(context, 0.5f);
CGContextSetRGBStrokeColor(context, 0.0, 2.0, 4.0, 1.0);
//need to add 100 lines form a certain radius to a max radius
for (float currentRadius = maxRadius; currentRadius > 99; currentRadius -=2.6) {
CGContextAddArc(context, centerPoint.x, centerPoint.y, currentRadius, 0.0, M_PI * 2.0, YES);
CGContextStrokePath(context);
}
}
@end