レイヤーを構築し、5 秒後に構築したいと考えています。しかし、最終的な値をレイヤーに割り当てる方法がわかりません。私のコードは次のとおりです。
-(CABasicAnimation *) buildIn{
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
animation.duration = 2.0f;
[animation setFromValue:[NSNumber numberWithFloat:0.0f]];
[animation setToValue:[NSNumber numberWithFloat:1.0f]];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
return animation;
}
-(CABasicAnimation *) buildOut{
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
animation.duration = 2.0f;
animation.beginTime = CACurrentMediaTime() + 5;
[animation setFromValue:[NSNumber numberWithFloat:1.0f]];
[animation setToValue:[NSNumber numberWithFloat:0.0f]];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
return animation;
}
- (IBAction)startAnimation:(id)sender {
[self.textView.layer addAnimation:[self buildIn] forKey:@"transparent"];
self.textView.layer.opacity = 1.0f;//I need to set the opacity to 1 after buildIn animation
[self.textView.layer addAnimation:[self buildOut] forKey:@"transparent"];
self.textView.layer.opacity = 0.0f;//ERROR: this is the final layer value, but I need to assign it after the build out animation, not here.
}
完了ブロックを使用して実行できると思いますが、見つかりません。