CALAYer的高度与旋转后显示的高度不同

时间:2016-02-25 09:12:50

标签: ios objective-c core-animation

CALayer' frame.size.height属性表示旋转变换后的高度。但我所看到的并非如此:

CATransform3D perspective = CATransform3DIdentity;
perspective.m34 = -1.0 / 300;
grayContainer.layer.sublayerTransform = perspective;

blackHeightIndicator = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 2, 100)];
blackHeightIndicator.backgroundColor = [UIColor blackColor];
[grayContainer addSubview:blackHeightIndicator];

redView = [[UIView alloc] init];
redView.backgroundColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:0.5];
redView.layer.anchorPoint = CGPointMake(0.5, 0);
redView.frame = CGRectMake(0, 0, 100, 100);
[grayContainer addSubview:redView];

CGFloat ang = 0.3 * M_PI;

redView.layer.transform = CATransform3DMakeRotation(ang, 1, 0, 0);

CGRect f1 = blackHeightIndicator.frame;
f1.size.height = redView.layer.frame.size.height;
blackHeightIndicator.frame = f1;

Screenshot

为什么呢?这里有一个演示项目:Demo Project

谢谢。

1 个答案:

答案 0 :(得分:1)

它与Graphical projection - Wikipedia

有关

你在模拟器中看到的是透视,投影线不平行,它们在同一点消失(这是你设置的m34值影响,并且不同的不同m34值)

但你得到的帧值是平行投影线

你可以从下面的图片右侧看到,在90度的情况下通知是如此明显我的意思

enter image description here

enter image description here