如何Facebook风格的过渡

要实现一个类似于Facebook和许多其他应用程序中使用的视图控制器转换,附加快照。 它需要使用CoreAnimation框架吗?还是可以在工具包中使用?

在这里输入图像说明

你必须使用CoreAnimation,除非你想导入某个人提出的第三方框架,但是使用CoreAnimation非常简单,我build议你学习它,因为它非常强大。 这是最简单的方法可以给你一个想法。 一旦你掌握了它,你可以自己构build一个更好的,以适应你的需求:

在你的viewcontroller有2个视图:

@interface yourViewController : UIViewController { // The facebook view in the example, this will be the view that moves. // Init this view with x=0 and let it cover the whole screen. IBOutlet UIView *topView; // The fb menu in the example // Init this view so that it stays behind the topView. IBOutlet UIView *bottomView; BOOL menuVisible; // init to false in viewDidLoad! } 

在界面构build器中创build它们,或者通过代码创build它们,但是您已经习惯了。 让他们重叠海誓山盟,让你只看到topView,并让buttomView留在它后面。

当用户按下button显示菜单时:

 -(IBAction)menuButtonPressed:(id)sender { // Set up animation with duration 0.5 seconds [UIView beginAnimations:@"ToggleMenu" context:nil]; [UIView setAnimationDuration:0.5]; // Alter position of topView CGRect frame = topView.frame; if (menuVisible) { frame.origin.x = 0; menuVisible = NO; } else { frame.origin.x = 300; //Play with this value menuVisible = YES; } topView.frame = frame; // Run animation [UIView commitAnimations]; } 

当然,你应该为“facebook view”和“menu view”实现你自己的UIView子类,并在上面的例子中用于topView和bottomView。

看看这个,它可能会给你一个起点: https : //github.com/Inferis/ViewDeck/