Je dessine sur un UIview plusieurs autres sous-vues. Ensuite, dans la méthode DrawRect de cet UIView, je dessine une courbe de Bézier.Dessin personnalisé Quartz et UIViews. Impossible de voir le dessin à quartz
MALHEUREUSEMENT, la courbe de bezier n'apparaît jamais. J'ai vérifié que la courbe de Bézier est derrière l'arrière-plan de la vue (quand je supprime la vue de fond, je peux le voir).
Comment combiner un dessin personnalisé avec Quartz et d'autres UISubviews?
Les vues UIV de la vue sont conservées dans un xib. Je charge le xib et ensuite je dessine la courbe dans la méthode Drawrect de la vue.
Ceci est le code de mise en œuvre du UIView dont je parle:
#import "DandiGameView.h"
#import "SeedView.h"
#import "Defines.h"
@implementation DandiGameView
@synthesize flowerHeadPosition, blowVolume, seedArray, trunkTop;
- (void)awakeFromNib {
[super awakeFromNib];
//self.clearsContextBeforeDrawing = YES;
[self animateTrunk:1 andWindVolume:1.0];
self.seedArray = [NSMutableArray array];
UIImageView *tmpImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"TRUNKTOP.PNG"]];
[tmpImageView setCenter:flowerHeadPosition];
self.trunkTop = tmpImageView;
[tmpImageView release];
//[tmpImageView sett]
[self addSubview:self.trunkTop];
[tmpImageView release];
}
- (id)initWithCoder:(NSCoder *)decoder
{
if (self = [super initWithCoder:decoder])
{
// Initialization code
float pointX = FLOWER_POSITION_HOR - FLOWER_TRUNK_WIDTH/2.0;
float topPointY = self.bounds.size.height - FLOWER_POSITION_VER;
flowerHeadPosition = CGPointMake(pointX, topPointY);
s = CGPointMake(pointX, self.bounds.size.height);
e = flowerHeadPosition;
cp1 = CGPointMake(pointX + 10.0, self.bounds.size.height - FLOWER_LOWER_CONTROLPOINT);
cp2 = CGPointMake(pointX - 10.0, self.bounds.size.height - FLOWER_UPPER_CONTROLPOINT);
}
return self;
}
- (void) animateTrunk:(double)time andWindVolume: (double) windVolume {
randOne = sin(0.2 * time * windVolume) + sin(0.5 * time* windVolume);
randTwo = sin(0.35 * time* windVolume) - sin(0.15 * time * windVolume);
flowerHeadPosition.x = FLOWER_POSITION_HOR - FLOWER_TRUNK_WIDTH/2.0 - randTwo * randOne * FLOWER_CURVITY_CONTROL;
cp1.x = FLOWER_POSITION_HOR - FLOWER_TRUNK_WIDTH/2.0 + 10 + randTwo * randOne * 2.0;
[self.trunkTop setCenter:flowerHeadPosition];
[self bringSubviewToFront:trunkTop];
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
CGContextRef c = UIGraphicsGetCurrentContext();
// Drawing with a GREEN stroke color
CGContextSetRGBStrokeColor(c, 141.0/255.0, 198.0/255.0, 63.0/255.0, 1.0);
// Draw them with a FLOWER_TRUNK_WIDTH stroke width so they are a bit more visible.
CGContextSetLineWidth(c, FLOWER_TRUNK_WIDTH);
// Draw a bezier curve with end points s,e and control points cp1,cp2
e = flowerHeadPosition;
CGContextMoveToPoint(c, s.x, s.y);
CGContextAddCurveToPoint(c, cp1.x, cp1.y, cp2.x, cp2.y, e.x, e.y);
CGContextStrokePath(c);
}
-(void)onElementTouch:(id)sender {
}
- (void) onTimeTick:(id)sender {
static float runningTime = 0.0;
runningTime += ANIMATION_TIME_STEP;
[self animateTrunk:runningTime andWindVolume:pow(blowVolume, 5.0)];
}
- (void)dealloc {
[trunkTop release];
[delegate release];
[super dealloc];
}
@end
J'ai fait exactement ce que vous avez dit (dans toutes les vues) mais je ne peux toujours pas voir le dessin. Si je mets la valeur alpha à une transparence totale ou partielle, alors je peux voir les dessins, mais bien sûr ils sont mélangés avec les autres vues. Je ne sais pas quoi faire d'autre. Je suis vraiment coincé ici. – Summon