Я пытаюсь добиться простого поведения:CABasicAnimation ручной прогресс от UISlider
Изменение opacity
из CALayer
используя значение UISlider
.
Я хочу сделать это с помощью CABasicAnimation
, то, что я написал с тех пор, хорошо работает, но когда ползунок имеет значение 1.0, непрозрачность возвращается к 0.0, тогда как она должна быть в 1.0 (окончательное запрошенное значение).
Вот код:
// Function called when slider changes values
- (IBAction)sliderDidChangeValue:(id)sender {
CABasicAnimation *anim = [self fader:1.0 from:0.0];
anim.timeOffset = ((UISlider*)sender).value;
// The animatedView gets the new animation with updated timeOffset
[self.animatedView.layer addAnimation:anim forKey:@"opacity"];
}
// This a simple helper function to create the fade animation
- (CABasicAnimation*)fader:(float)to from:(float)from{
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"opacity"];
anim.fromValue = [NSNumber numberWithFloat:from];
anim.toValue = [NSNumber numberWithFloat:to];
anim.fillMode = kCAFillModeForwards;
anim.speed = 0.0;
anim.duration = 1.0;
anim.removedOnCompletion = NO;
return anim;
}
Значение ползунка используется для смещения по времени. – jrturton