我正在尝试创建自定义 UIView 转换。基本上,当呈现某个模态视图时,它所覆盖的 View 就会移到背景中。
为了实现这一点,我使用核心动画来操纵 View 层上的 CATransform3D,我正在移动到背景,然后在其上呈现模态视图。
为了将 View 移到背景中,我正在创建一个 CABasicAnimation 来为 CATransform3D 中的变化设置动画,如下所示
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
CATransform3D toTransform = CATransform3DIdentity;
toTransform.m34 = 1.0f / -500.0f;
toTransform = CATransform3DTranslate(toTransform, 0.0f, 0.0f, -40.0f);
[animation setFromValue:[NSValue valueWithCATransform3D:CATransform3DIdentity]];
[animation setToValue:[NSValue valueWithCATransform3D:toTransform]];
[animation setDuration:1.0f];
self.menuView.layer.transform = toTransform;
[self.menuView.layer addAnimation:animation forKey:@"moveBackAnimation];
self.menuView 是我要移回的 View 。
在我添加模态视图之前,这非常有用。
RVLAddViewController *addViewController = [[RVLAddViewController alloc] initWithNibName:@"RVLAddViewController" bundle:nil];
[self presentViewController:addViewController animated:YES completion:nil];
当按下按钮时,我会在动画下方调用此代码。如果此代码不存在,则一切都按预期工作, View 看起来只是逐渐消失,然后停留在那里。
当模态视图呈现时,它不会逐渐淡入远处,而是缩小到较小的尺寸并移动到左上角。
我会尽快上传一个示例应用程序,github 现在挂了。 编辑 不需要 - 已经给出了解决方案! /编辑
最佳答案
我弄乱了一段时间,看起来它与自动布局有关。如果您关闭它,它会按您预期的那样工作。
关于ios - 呈现模态视图 Controller 时,核心动画层表现得很奇怪。 CATransform3D 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14007996/