FlyingImagesに基づくコア アニメーション トランジションをいじっています。
トランジションが進むにつれて不透明度を 0 から 1 に設定し、反転するにつれて不透明度を 0 に戻せるようにしたいと考えています。
これは私が現在いる場所です:
- (CATransform3D)originTransformForLayer:(CALayer *)layer; {
CGPoint layerPosition = [layer position];
CATransform3D originTransform = CATransform3DMakeTranslation(20.f - layerPosition.x, -layerPosition.y, 0.f);
return originTransform;
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[[self durationStepper] setIncrement:.05f];
[[self durationStepper] setDoubleValue:.4f];
shouldReverse_ = NO;
//Start with all of the images at the origin
[CATransaction begin];
[CATransaction setDisableActions:YES];
for (CALayer *imageLayer in [[[self imageContainer] layer] sublayers]) {
[imageLayer setOpacity:0];
[imageLayer setTransform:[self originTransformForLayer:imageLayer]];
// NSLog(@"tag: %@", [[[self imageContainer] layer] sublayers] );
}
[CATransaction commit];
}
- (IBAction)runAnimation:(id)sender {
CALayer *containerLayer = [[self imageContainer] layer];
NSTimeInterval delay = 0.2f;
NSTimeInterval delayStep = .05f;
NSTimeInterval singleDuration = [[self durationStepper] doubleValue];
NSTimeInterval fullDuration = singleDuration + (delayStep * [[containerLayer sublayers] count]);
NSEnumerator *imageLayerEnumerator;
if(shouldReverse_) {
newTransform = [self originTransformForLayer:imageLayer];
[imageLayer setOpacity:0];
} else {
[imageLayer setOpacity:1];
newTransform = CATransform3DIdentity;
}
for (CALayer *imageLayer in imageLayerEnumerator) {
CATransform3D currentTransform = [[imageLayer presentationLayer] transform];
CATransform3D newTransform;
if(shouldReverse_) {
newTransform = [self originTransformForLayer:imageLayer];
} else {
newTransform = CATransform3DIdentity;
}
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"transform"];
anim.beginTime = delay;
anim.fromValue = [NSValue valueWithCATransform3D:currentTransform];
anim.toValue = [NSValue valueWithCATransform3D:newTransform];
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
anim.fillMode = kCAFillModeBackwards;
anim.duration = singleDuration;
CAAnimationGroup *group = [CAAnimationGroup animation];
group.animations = [NSArray arrayWithObject:anim];
group.duration = fullDuration;
[imageLayer setTransform:newTransform];
[imageLayer addAnimation:group forKey:@"transform"];
delay += delayStep;
}
shouldReverse_ = !shouldReverse_;
}
しかし、それはハックであり、私はそれが好きではありません..