2

正面図と背面図がある名刺を作成しました。正面図をタップすると、UIView が反転し、ビューの裏側が表示されます。

これが私が試しているコードです:

 CATransform3D transform = CATransform3DMakeRotation(M_PI, 0, 1, 0);
 transform.m34 = 1.0/700.0;


 CABasicAnimation *rotation = [CABasicAnimation animationWithKeyPath:@"transform"];
 rotation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
 rotation.toValue = [NSValue valueWithCATransform3D:transform];
 rotation.duration = DURATION;

 CABasicAnimation *translation = [CABasicAnimation animationWithKeyPath:@"position"];
 translation.fromValue = [NSValue valueWithCGPoint:CGPointMake(self.imageview.center.x,[[self.imageview superview] center].y-45)];
 translation.toValue = [NSValue valueWithCGPoint:CGPointMake(_frame.origin.x+_frame.size.width/2,
                                                             _frame.origin.y+_frame.size.height/2)];
 translation.duration = DURATION;


 CABasicAnimation *translation = [CABasicAnimation animationWithKeyPath:@"position"];
 translation.fromValue = [NSValue valueWithCGPoint:CGPointMake(self.imageview.center.x,[[self.imageview superview] center].y-45)];
 translation.toValue = [NSValue valueWithCGPoint:CGPointMake(_frame.origin.x+_frame.size.width/2,
                                                             _frame.origin.y+_frame.size.height/2)];
 translation.duration = DURATION;
 CAAnimationGroup *group = [CAAnimationGroup animation];

 group.animations = @[ translation, rotation ];
 group.duration = DURATION;
 group.delegate = self;
 group.fillMode = kCAFillModeForwards;
 group.removedOnCompletion = NO;
 [layer addAnimation:group forKey:nil];

上記のコードは、単一のビューで完全に機能します。2 番目のビューを組み合わせて、前面と背面から反転効果を得る方法。

ここに画像の説明を入力

4

1 に答える 1

3

コア アニメーションの使用

コンテナ ビューには前面と背面の両方を追加できます。背面図は Y を中心に 180 度回転し、正面図は通常の状態になります。両方のレイヤーが片面になります (設定によりlayer.doubleSided = NO;.

次に、回転を適用すると、コンテナー ビューの回転をアニメーション化して、前面と背面の両方が同時にアニメーション化されるようにします。

UIView トランジション

または、組み込みのフリップアニメーションを使用することもできます

transitionFromView:toView:duration:options:completion:

UIViewAnimationOptionTransitionFlipFromLeftオプションにまたはを渡しUIViewAnimationOptionTransitionFlipFromRightます。

于 2013-06-25T11:57:22.670 に答える