6

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

enter image description here

+0

它在Cocoa Touch中不可用,您将不得不在屏幕上查看和查看控制器,并自行将顶部拖动到一边。 – 2012-07-11 13:25:00

+0

任何入门的东西/资源? – Firdous 2012-07-11 13:25:53

+0

对不起。我不知道任何好资源 – 2012-07-11 13:29:43

回答

4

你,除非你想导入第三部分框架,有人建议使用CoreAnimation,但它是使用CoreAnimation非常简单,我建议你学习它,因为它非常强大。这是给你一个想法的最简单的方法。

在您的视图控制器有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! 
} 

在界面生成器,或通过代码或然创建他们,一旦你得到它的窍门,以满足您的需求,您可以构建更好自己一点你习惯了。让它们重叠,让你只能看到topView,并让buttomView留在它后面。

当用户按下按钮,显示菜单:

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

当然,你应该实现自己的UIView子类“脸谱视图”和“菜单视图”等,并使用冠捷和在上面的例子中的bottomView。

+0

嗨我也试图在我的iPhone应用程序中实现相同的功能。按照您的建议,我使用了两个UIViews,并使用toggleMenu动画来滑动topView。但是因为我有一个UINavigationController,它不会随着topView滑动,它只是保持在同一个位置。我能做些什么呢?非常感谢你的建议。 – Yasodha 2012-08-28 10:15:03

+0

由于这是“自己动手”解决方案,因此将其与UINavigationController结合起来会很复杂。如果您无法使用位于视图之上的NavigationController,则可以停止使用它并制作自己的导航栏(我会推荐这个),也可以在菜单可见的时候隐藏它。我相信有一些方法可以将它推到一边,但是我没有看到足够的价值来尝试了解... – 2012-09-10 08:08:43

+0

@ user1280436您尝试使用navigationcontroller.view来动画,然后导航栏也会生成动画。请尝试一下我以前没做过。 – 2012-10-30 05:55:04

1

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

+0

您好我也试图在我的iPhone应用程序中实现相同的功能。我按照建议使用了两个UIViews,并使用toggleMenu动画来滑动topView。但是因为我有一个UINavigationController,它不会随着topView滑动,它只是保持在同一个位置。我能做些什么呢?非常感谢你的建议。提前致谢。 – Yasodha 2012-08-28 12:27:46