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