简体   繁体   English

UIView滑动过渡淡出

[英]UIView sliding transition fades

I've got some code inside one of my view controllers that will make sliding transition from one view to another: 我的一个视图控制器中有一些代码,这些代码可以实现从一个视图到另一个视图的滑动过渡:

-(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"];
}

The sliding transition seems to work correctly, but I'm also seeing the new view fade in from a blank screen in addition to the sliding. 滑动过渡似乎正常工作,但除了滑动之外,我还看到新视图从空白屏幕淡入。 I suspect that this is because I'm adding a new view to the super view that wasn't there before. 我怀疑这是因为我要在超级视图中添加以前不存在的新视图。 What I'd like to do is the same thing, but without the fading in. How can I do this? 我想做的是同一件事,但又不褪色。我该怎么做?

I think the kCATransitionPush transition does a fade at the same time by design. 我认为kCATransitionPush过渡在设计上会同时消失。 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:. 使用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. 传递UIViewAnimationOptionTransitionNone作为过渡选项,然后使用动画块将当前视图移出屏幕,同时从相反方向在屏幕上滑动新视图。

I don't have a straight answer to your issue but one way I found out for handling transition between two views is to add the new view to your superview like you did, take a screenshot of each view, realize the animation and remove the two screenshots views when the transition is done. 对于您的问题,我没有一个直接的答案,但是我发现要处理两个视图之间的过渡的一种方法是像您一样将新视图添加到您的超级视图中,对每个视图进行截图,实现动画并删除两个视图完成转换后,将屏幕截图显示在屏幕上。 I explained more in detail what i did here and it works very well. 我更详细地解释了我在这里所做的事情 ,并且效果很好。 I think it worth a try to resolve the problem you are facing. 我认为值得尝试解决您面临的问题。 Any reason otherwise you don't use the animateWithDuration method on UIView? 是否有其他原因导致您不在UIView上使用animateWithDuration方法?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM