J'utilise le code suivant et il dessine un triangle sur l'écran. Mais pour une raison quelconque, il affiche le triangle ci-dessous.Pourquoi mon triangle Core Graphics est-il inversé lorsque je le dessine?
Voici le code:
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path,NULL,10.0f, 100.0f);
CGPathAddLineToPoint(path,NULL,100.0f,10.0f);
CGPathAddLineToPoint(path,NULL,100.0f,100.0f);
CGPathAddLineToPoint(path,NULL,100.0f,100.0f);
CGPathCloseSubpath(path);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(ctx, [UIColor blueColor].CGColor);
CGContextAddPath(ctx, path);
CGContextFillPath(ctx);
}
et est ici le résultat:
/|
/|
/|
/ |
/ |
/__ __|
Mais quand je dessine sur le papier, je suis venu à ce schéma:
___________
\ |
\ |
\ |
\ |
\\ |
\
\|
(bien vous avez l'idée juste)
Qu'est-ce qui me manque? Peut-être que je ne pense pas directement. x est horizontal et y est vertical. (0,0) est le droit d'origine.
Comment puis-je faire cela? – azamsharp
CGAffineTransform flipVertical = CGAffineTransformMake (1, 0, 0, -1, 0, self.bounds.size.height); CGContextConcatCTM (ctx, flipVertical); –
Merci un million cela a fonctionné! Je suis un débutant complet en IPhone alors merci de m'avoir aidé! – azamsharp