UIImage auf UIBezierPath zeichnen

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • UIImage auf UIBezierPath zeichnen

    Hallo, ich hab auch mal wieder eine Frage an euch. Ich benutze die Library timelineIOS, um eine Zugverbindung darzustellen. Leider bietet diese nur runde Kreise und keine ovale/ellipsen. Daher habe ich das ganze selber implementiert und es sieht nun so aus: (Anhang 1).

    Jedoch möchte ich jetzt in diesen Ovalen ein Bild zeichnen. Gewünschtes Verhalten seht ihr hier: (Anhang 2).

    Hier noch der relevante Code Ausschnitt :

    Quellcode

    1. UIBezierPath *circle;
    2. CAShapeLayer *circleLayer;
    3. circle = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(5, yCenter-7, 25, 15) cornerRadius: 12];
    4. circleLayer = [CAShapeLayer layer];
    5. circleLayer.path = circle.CGPath;
    6. circleLayer.strokeColor = [UIColor orangeColor].CGColor;
    7. circleLayer.fillColor = [UIColor orangeColor].CGColor;
    8. circleLayer.lineWidth = LINE_WIDTH;
    9. if(self.showTrainImage) {
    10. //zug bild auf oval zeichnen
    11. }
    12. else if(self.showBusImage) {
    13. //bus bild auf oval zeichnen
    14. }
    15. else {
    16. //fußweg bild auf oval zeichnen
    17. }
    Alles anzeigen
    Dateien
    • bild1.png

      (118,17 kB, 249 mal heruntergeladen, zuletzt: )
    • bild2.png

      (43,51 kB, 242 mal heruntergeladen, zuletzt: )
  • Hm hab das mal gerade versucht per:

    Quellcode

    1. circleLayer.contents = (__bridge id)[UIImage imageNamed:@"bus"].CGImage;


    dann wird der layer zu einem array hinzugefügt :

    Quellcode

    1. [circleLayers addObject:circleLayer];


    Zum Schluss werden die hinzugefügten layer animiert:

    Quellcode

    1. [self startAnimatingLayers:circleLayers forStatus:currentStatus];


    Das hier ist die entsprechende Methode:

    Quellcode

    1. - (void)startAnimatingLayers:(NSArray *)layersToAnimate forStatus:(int)currentStatus {
    2. float circleTimeOffset = 1;
    3. circleCounter = 0;
    4. int i = 1;
    5. if (currentStatus == layersToAnimate.count) {
    6. //add without animation
    7. for (CAShapeLayer *cilrclLayer in layersToAnimate) {
    8. [self.progressViewContainer.layer addSublayer:cilrclLayer];
    9. }
    10. for (CAShapeLayer *lineLayer in layers) {
    11. [self.progressViewContainer.layer addSublayer:lineLayer];
    12. }
    13. } else {
    14. //add with animation
    15. for (CAShapeLayer *cilrclLayer in layersToAnimate) {
    16. [self.progressViewContainer.layer addSublayer:cilrclLayer];
    17. CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    18. animation.duration = 0.2;
    19. animation.beginTime = [cilrclLayer convertTime:CACurrentMediaTime() fromLayer:nil] + circleTimeOffset;
    20. animation.fromValue = [NSNumber numberWithFloat:0.0f];
    21. animation.toValue = [NSNumber numberWithFloat:1.0f];
    22. animation.fillMode = kCAFillModeForwards;
    23. animation.delegate = self;
    24. circleTimeOffset += .4;
    25. [cilrclLayer setHidden:YES];
    26. [cilrclLayer addAnimation:animation forKey:@"strokeCircleAnimation"];
    27. if (i == currentStatus && i != [layersToAnimate count]) {
    28. CABasicAnimation *strokeAnim = [CABasicAnimation animationWithKeyPath:@"strokeColor"];
    29. strokeAnim.fromValue = (id) [UIColor orangeColor].CGColor;
    30. strokeAnim.toValue = (id) [UIColor clearColor].CGColor;
    31. strokeAnim.duration = 1.0;
    32. strokeAnim.repeatCount = HUGE_VAL;
    33. strokeAnim.autoreverses = NO;
    34. [cilrclLayer addAnimation:strokeAnim forKey:@"animateStrokeColor"];
    35. }
    36. i++;
    37. }
    38. }
    39. }
    Alles anzeigen


    Leider wird das Bild nicht gezeichnet, was mache ich falsch ?

    EDIT: Ich calle auch teilweise

    Quellcode

    1. ​setNeedsUpdateConstraints
    Kann es daran liegen ? Ich bin mir unsicher, ob beim update der constrains auch ein

    Quellcode

    1. setNeedsDisplay
    gecallt wird, weil dann ja klar wäre warum das Bild nicht gezeichnet wird.

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von da_eh ()