0

2 つの UIView に y 軸を中心に CATransform3DRotate を適用すると、それらの z 順序が逆になっているように見えます。z 軸に回転して戻った UIView のセクションは、画面に向かって回転したセクションの前に表示されます。このアニメーションは、私が何を意味するかを示しています:

回転アニメーション

zオーダーが期待どおりに動作するようにするにはどうすればよいですか?

そのアニメーションを生成するために使用したコードは以下のとおりです (double[UIView animateWithDuration]は完全な回転に適切に必要です)。

@interface ViewController ()

@property (strong, nonatomic) UIView *blueSquare;
@property (strong, nonatomic) UIView *redSquare;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.blueSquare = [[UIView alloc] initWithFrame:(CGRect){.origin = {160,234}, .size = {400,300}}];
    self.blueSquare.backgroundColor = [UIColor blueColor];
    [self.view addSubview:self.blueSquare];

    self.redSquare = [[UIView alloc] initWithFrame:(CGRect){.origin = {464,234}, .size = {400,300}}];
    self.redSquare.backgroundColor = [UIColor redColor];
    [self.view addSubview:self.redSquare];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    [UIView animateWithDuration:5 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
        CATransform3D transform = CATransform3DIdentity;

        transform.m34 = 1.0/900.0;  // for perspective

        transform = CATransform3DRotate(transform, M_PI, 0, 1, 0);

        self.blueSquare.layer.transform = transform;
        self.redSquare.layer.transform = transform;
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:5 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
            CATransform3D transform = CATransform3DIdentity;

            transform.m34 = 1.0/900.0;  // for perspective

            transform = CATransform3DRotate(transform, 2*M_PI-0.001, 0, 1, 0);

            self.blueSquare.layer.transform = transform;
            self.redSquare.layer.transform = transform;
        } completion:nil];
    }];
}

@end
4

1 に答える 1

2

トランスフォームのパースペクティブは反転しています。通常m34、変換の (変換行列の 3 列目、4 行目) コンポーネントには負の値を使用します。

于 2014-07-10T16:33:29.640 に答える