2

我正在尝试创建自定义 UIView 过渡。基本上,当呈现某个模态视图时,它所覆盖的视图会移动到背景中。

为了实现这一点,我使用 Core 动画来操作视图层上的 CATransform3D,我将移至背景,然后在其上呈现模态视图。

要将视图移动到背景中,我正在创建一个 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 是我要向后移动的视图。

在我添加模态视图之前,这很好用。

RVLAddViewController *addViewController = [[RVLAddViewController alloc] initWithNibName:@"RVLAddViewController" bundle:nil];
[self presentViewController:addViewController animated:YES completion:nil];

当按下按钮时,我在动画下方调用此代码。如果未显示此代码,则每件事情都按预期工作,视图看起来就像它只是淡入远处然后它停留在那里。

当模态视图出现时,它不会逐渐消失在远处,而是向下射击到较小的尺寸并移动到左上角。

我会尽快上传一个示例应用程序,github 现在已经关闭。编辑不需要 - 已经给出了解决方案!/编辑

4

1 回答 1

1

我搞砸了一段时间,看起来它与自动布局有关。如果你把它关掉,它会像你期望的那样工作。

于 2012-12-23T05:58:48.720 回答