简单核心动画:UIView的3D变换

17

我想用Core Animation(CA)制作简单的部分翻转动画,但是在透视方面遇到了问题。我尝试过:

    [UIView animateWithDuration:1.0 animations:^{
    self.someView.layer.anchorPoint = CGPointMake(0.5, 0);
    self.someView.layer.transform = CATransform3DMakeRotation(M_PI*0.6,1.0,0.0,0.0);
} completion:^(BOOL finished){
    // code to be executed when flip is completed
}];

如何获得这种漂亮的视角?

输入图像描述


1
重复的问题?-https://dev59.com/ynRC5IYBdhLWcg3wSu97 - Justin Meiners
2个回答

33

像这样就可以了:

CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
rotationAndPerspectiveTransform.m34 = 1.0 / -1000.0;
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, M_PI * 0.6, 1.0f, 0.0f, 0.0f);
[UIView animateWithDuration:1.0 animations:^{
    self.someView.layer.anchorPoint = CGPointMake(0.5, 0);
    self.someView.layer.transform = rotationAndPerspectiveTransform;
} completion:^(BOOL finished){
    // code to be executed when flip is completed
}];

几乎就是那样,但需要在外面而不是里面。灰线固定在图像上。 - dormitkon
稍微调整了一下m34属性,(1.0/-1000),现在看起来很不错 :) 谢谢 - dormitkon

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接