How do I stack images to simulate depth using Core Animation?

前端 未结 2 1802
忘掉有多难
忘掉有多难 2020-12-08 08:43

I have a series of UIImages with which I need to simulate depth. I can\'t use scaling because I need to be able to rotate the parent view, and the images should look like t

2条回答
  •  渐次进展
    2020-12-08 09:15

    I finally solved this by using CATransform3DMakeTranslation, which seems to be the only way to move a layer up or down the z-axis:

    UIImageView *three = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"3.png"]];
    three.layer.transform = CATransform3DMakeTranslation(0.0f, 0.0f, 20.0f);
    three.center = CGPointMake(160 + 60, 240 - 60);
    [self.view addSubview:three];
    

    (I also moved UIImageView one -20.0f pixels on the z-axis. That finally gave the effect I was looking for.)

提交回复
热议问题