0

我的一个视图控制器中有一些代码可以从一个视图滑动过渡到另一个视图:

-(void)transitionToNewView:(UIView*)newView
{

    UIView *superView = [self.view superview]; 
    [superView addSubview:newView]; 
    newView.frame = superView.bounds;
    [self.view removeFromSuperview]; 

    CATransition *animation = [CATransition animation]; 
    [animation setDuration:0.5]; 
    [animation setType:kCATransitionPush];
    [animation setSubtype:kCATransitionFromLeft]; 
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

    [[superView layer] addAnimation:animation forKey:@"keygoeshere"];
}

滑动过渡似乎工作正常,但除了滑动之外,我还看到新视图从空白屏幕淡入。我怀疑这是因为我正在向以前不存在的超级视图添加一个新视图。我想做的是同样的事情,但没有淡入。我该怎么做?

4

2 回答 2

1

I think the kCATransitionPush transition does a fade at the same time by design. I could swear I remember reading that somewhere.

It would be pretty simple to construct a view-to-view push transition using the method transitionFromView:toView:duration:options:completion:.

Pass in UIViewAnimationOptionTransitionNone for the transition option, and then use an animation block that slides the current view off-screen while sliding the new view on-screen from the opposite direction.

于 2012-06-06T23:37:47.253 回答
0

我对您的问题没有直接的答案,但我发现处理两个视图之间的转换的一种方法是像您一样将新视图添加到您的超级视图,截取每个视图的屏幕截图,实现动画并删除这两个视图转换完成时的屏幕截图视图。我更详细地解释了我在这里所做的事情,并且效果很好。我认为值得尝试解决您面临的问题。有什么理由不使用 UIView 上的 animateWithDuration 方法吗?

于 2012-06-06T21:38:27.733 回答