本文介绍了iPhone CATransition为任何动画的开始和结束添加了淡入淡出效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我刚刚开始为iphone开发一些简单的应用程序。我会说我很确定我对多个视图的编程没有很强的理解,但是我正在努力学习。

So I am just beginning recently developing some simple apps for the iphone. I will say that I am fairly sure I don't have a strong understanding of programming for multiple views yet, but I am trying to learn as I go.

我有一个以普通窗口为基础的应用程序启动的程序,所以我可以手工编写所有内容,希望能够更多地了解我正在做的事情。我有一个视图控制器,用于根据每个其他视图控制器的请求加载和释放视图。没有元素从一个视图持续到另一个视图。

I have a program that started as a plain window based application so i could hand write everything in hopes of learning more about what i am doing. I have a single view controller that acts to load and release views as requested from each of the other view controllers. No elements persist from one view to the other.

我目前工作正常,但我想在视图更改中添加动画。一个简单的推动画是我的目标。当新视图推进时,一个视图就会推出。

I have that working fine currently, but I wanted to add animations to the view changing. A simple push animation was my goal. One view pushes out as the new view pushes in.

查看CATransitions并尝试使用它,我有一个工作版本(目前用于推动顶部/底部)

Looking into CATransitions and trying that, I have a working version (currently for pushing top/bottom)

        [thisView.view removeFromSuperview];
        [thisView release];
        thisView = [[MenuViewController alloc] initWithNibName:@"MenuView" bundle:nil];
        [self.view addSubview:thisView.view];   

        CATransition *animation = [CATransition animation];
        [animation setDuration:6.3];
        [animation setType:kCATransitionPush];
        [animation setSubtype:kCATransitionFromTop];
        [animation setRemovedOnCompletion:YES];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
        [[self.view layer] addAnimation:animation forKey:nil];

据我所知,这是使用CATransition的非常标准的代码,它可以做我做的事情需要时,一个视图会在另一个视图进入时被推高。但是我的问题是,每个视图分别进入或退出时似乎都会出现淡入淡出。

as far as I can tell this is pretty standard code for using CATransition and it works to do what I need, one view gets pushed up as the other view comes in. However my problem is that there seems to be a fade that happens to each view as they come in or go out respectively.

同样 - 在这个例子中;当菜单从底部向上推时,它将从白色慢慢淡入,并且当前一个视图离开屏幕时,它将慢慢淡入白色。

As such - in this example; as the menu pushes up from the bottom, it will very slowly fade in from white, and as the previous view leaves the screen it will slowly fade to white.

请注意,持续时间设置为6,因此褪色是戏剧性的。

Note that the duration is set to 6 so that the fading is dramatic.

有没有办法去除这里的褪色,以便每个视图在进入和离开的路上都保持稳定?或者我在这条路线上完全错过了标记?

Is there a way to remove the fading here so that each view remains solid on the way in and the way out? Or have I missed the mark completely in this route that I am taking?

我感谢任何帮助。道歉我已经啰嗦了。

I appreciate any help. Apologies I have been long winded.

推荐答案

我从来没有找到解决这个问题的方法,但我可以提供一个合理的解决方法。发生的事情是它不会褪色到白色,而是褪色到透明,窗口背景(或任何视图背后)是白色的。有几种方法可以解决这个问题:

I have never been able to find a solution to this problem, but I can offer a reasonable workaround. What's happening is it isn't fading to white, but fading to transparent, and the window background (or whatever view is behind) is white. There are a couple ways to get around this:


  1. 更改窗口背景颜色。如果你褪色的两个视图都具有相同的纯色背景,那么这看起来会很不错。

  1. Change the window background color. If both views you're fading between have the same solid background color, then this will look pretty good.

不要在每个视图中渲染背景( MenuView,例如),而是拥有一直在这些视图下的共享背景视图。

Don't render a background in each view ("MenuView," for example), but rather have a shared background view that's under those views at all times.

请注意,这不适用于所有情况 - 例如,分组 UITableView s总是完全不透明。

Note that this will not work in all circumstances -- grouped UITableViews, for example, are always completely opaque.

(正如我注意到的,我假设您没有构建基于导航的应用程序,在这种情况下,应该自动处理所有动画。)

(As I side note, I assume that you aren't build a navigation-based application, in which case all the animation should be handled automatically.)

您还可能要考虑查看 UIView 方法 setAnimationTransition:forView:cache:如果还没有另外在视图之间转换的方法(虽然它不能做滑动动画,如果你设置了那个)。

You also might want to consider the looking into the UIView method setAnimationTransition:forView:cache: if you haven't already as another way to transition between views (although it cannot do a sliding animation, if you are set on that).

这篇关于iPhone CATransition为任何动画的开始和结束添加了淡入淡出效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 19:08