How to perform kCATransitionPush animation without any transparency / fade effects [duplicate]

假装没事ソ 提交于 2020-02-21 11:10:11

问题


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];

回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/2687363/how-to-perform-kcatransitionpush-animation-without-any-transparency-fade-effec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!