如何在没有任何透明度/淡入淡出效果的情况下执行 kCATransitionPush 动画

发布于 2024-08-29 10:06:11 字数 1105 浏览 2 评论 0原文

可能的重复:
iPhone CATransition 添加淡入淡出效果任何动画的开始和结束?

我试图复制 [UIViewController PresentModalViewController:animated:] 执行的“从底部向上滑动”动画,但不调用它,因为我不想要模态视图。

下面的核心动画代码非常接近,但似乎正在改变视图的透明度值。在动画开始时,您可以通过向上滑动的视图部分看到。在动画的中间/结束时,我们滑过的视图是完全透明的,因此我们可以看到它后面。我希望两者在动画过程中都保持完全不透明。

关于如何停止此代码中的透明度更改或以其他方式获得我正在寻找的“向上滑动动画”而不需要模态视图的任何想法?

UIViewController *nextViewController = [[UIViewController alloc] autorelease];
nextViewController.view.backgroundColor = [UIColor redColor];  
CATransition *animation = [CATransition animation];
animation.duration = 3.5;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
animation.type = kCATransitionPush;
animation.subtype = kCATransitionFromTop;  
[self.navigationController pushViewController:nextViewController animated:NO];
[self.navigationController.view.layer addAnimation:animation forKey:nil];

Possible Duplicate:
iPhone CATransition adds a fade to the start and end of any animation?

I'm trying to duplicate the "slide up from the bottom" animation that [UIViewController presentModalViewController:animated:] performs but without calling it because I don't want a modal view.

The below core animation code comes very close but appears to be changing transparency values of the views during it. At the start of the animation you can partially see through the view sliding up. By the middle/end of the animation the view we are sliding over is fully transparent so we can see behind it. I'd like both to remain fully opaque during this animation.

Any ideas on how to stop transparency changes in this code or to otherwise get the "slide up animation" I am looking for without requiring a modal view?

UIViewController *nextViewController = [[UIViewController alloc] autorelease];
nextViewController.view.backgroundColor = [UIColor redColor];  
CATransition *animation = [CATransition animation];
animation.duration = 3.5;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
animation.type = kCATransitionPush;
animation.subtype = kCATransitionFromTop;  
[self.navigationController pushViewController:nextViewController animated:NO];
[self.navigationController.view.layer addAnimation:animation forKey:nil];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

划一舟意中人 2024-09-05 10:06:11

最简单的方法是简单地使用 UIView beginAnimations/commitAnimations 块。您可以通过查看文档来调整持续时间和曲线。

{   
    // Adjust for orientation as necessary.
    view.frame = CGRectMake(0,
                        -480, 
                        320,
                        480);

    [UIView beginAnimations:nil context:nil];

    view.frame = CGRectMake(view.frame.origin.x,
                        0, 
                        view.frame.size.width,
                        view.frame.size.height);

    [UIView commitAnimations];
}

此处的文档:

http://developer. apple.com/library/ios/#documentation/uikit/reference/UIView_Class/UIView/UIView.html

The simplest method is to simply use UIView beginAnimations/commitAnimations block. You can adjust the duration and curve by reviewing the docs.

{   
    // Adjust for orientation as necessary.
    view.frame = CGRectMake(0,
                        -480, 
                        320,
                        480);

    [UIView beginAnimations:nil context:nil];

    view.frame = CGRectMake(view.frame.origin.x,
                        0, 
                        view.frame.size.width,
                        view.frame.size.height);

    [UIView commitAnimations];
}

Docs here:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIView_Class/UIView/UIView.html

花海 2024-09-05 10:06:11

除了 CATransition,您还可以尝试使用 CABasicAnimation,将位置从屏幕顶部动画到所需的位置。

Instead of the CATransition, you could instead try using a CABasicAnimation that animates the position from off the top of the screen into the desired position.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文