يختفي مسار Cashapelayer بعد الرسوم المتحركة - حاجة إليها للبقاء في نفس المكان

StackOverflow https://stackoverflow.com/questions/2233601

سؤال

بفضل بعض المساعدة في Stackoverflow، أقوم حاليا بالتحريك مسارا في Cashapelayer لجعل مثلث يشير من عفريت متحرك إلى نقطة نقل أخرى على الشاشة.

بمجرد اكتمال الرسوم المتحركة، يختفي المثلث من الشاشة. أنا أستخدم فترات قصيرة للغاية لأن هذا الرمز يتم إطلاقه كل .1 من الثانية لكل من العفاريت. والنتيجة هي مسارات المثلث الأحمر بشكل صحيح، لكنها تومض بسرعة أو ليس هناك كليا. عندما أرادت المدة، يمكنني رؤية مثلث البقاء لفترة أطول.

ماذا يمكنني أن أفعل للحصول على مثلث للبقاء على الشاشة، مع ذلك المسار الحالي ( tovalue) حتى يتم استدعاء الطريقة مرة أخرى لتحريك من البقعة إلى المكان التالي؟ حاولت تحديد إزالتها و Removeallanimations، ولكن دون جدوى.

الرمز أدناه:

-(void)animateConnector{

//this is the code that moves the connector from it's current point to the next point
//using animation vs. position or redrawing it

    //set the newTrianglePath
    newTrianglePath = CGPathCreateMutable();
    CGPathMoveToPoint(newTrianglePath, nil, pointGrid.x, pointGrid.y);//start at bottom point on grid
    CGPathAddLineToPoint(newTrianglePath, nil, pointBlob.x, (pointBlob.y - 10.0));//define left vertice
    CGPathAddLineToPoint(newTrianglePath, nil, pointBlob.x, (pointBlob.y + 10.0));//define the right vertice
    CGPathAddLineToPoint(newTrianglePath, nil, pointGrid.x, pointGrid.y);//close the path
    CGPathCloseSubpath(newTrianglePath);
    //NSLog(@"PointBlob.y = %f", pointBlob.y);

    CABasicAnimation *connectorAnimation = [CABasicAnimation animationWithKeyPath:@"path"];`enter code here`
    connectorAnimation.duration = .007; //duration need to be less than the time it takes to fire handle timer again
    connectorAnimation.removedOnCompletion = NO;  //trying to keep the the triangle from disappearing after the animation
    connectorAnimation.fromValue = (id)trianglePath;  
    connectorAnimation.toValue = (id)newTrianglePath;
    [shapeLayer addAnimation:connectorAnimation forKey:@"animatePath"];


    //now make the newTrianglePath the old one, so the next animation starts with the new position 2.9-KC
    self.trianglePath = self.newTrianglePath;

}
هل كانت مفيدة؟

المحلول

المشكلة هي Fillmode على الرسوم المتحركة الخاصة بك. الافتراضي ل Fillmode هو "kcafillmoderemoved" والتي ستزيل الرسوم المتحركة عند الانتهاء.

افعل هذا:

connectorAnimation.fillMode = kCAFillModeForwards;

هذا يجب أن تفعل ذلك.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top