我正在尋找Facebook式的滑動式UITableView。瞬間移動UINavigationView - Facebook風格
我已經做到了這一點,動畫和陰影,應有盡有。我擔心的是,我以完全錯誤的方式來做,而且事情並不完全正確。
該應用程序具有一個UINavigationController的UIView控件(UIWindow)。 UINavigationController(它的根視圖控制器)內部的視圖設置了其leftBarButtonItem屬性。這是按下按鈕時運行的代碼。
- (void)showFeedList {
//set the feed list as showing even before it is
feedListShowing = YES;
//to show the feed list, we need to instanciate one
feedSelectionListViewController = [[FeedSelectionListViewController alloc] initWithNibName: @"FeedSelectionListViewController" bundle: nil];
//set the frame to 200 points to the left of the screen
feedSelectionListViewController.view.frame = CGRectOffset(feedSelectionListViewController.view.frame, -200, 20);
NSInteger offset = feedSelectionListViewController.view.frame.size.width;
//store a pointer to the root navigation controller, and add the list view controller's view to the navigation controller's view
UINavigationController *navigationController = (UINavigationController *)UIApplication.sharedApplication.delegate.window.rootViewController;
[navigationController.view addSubview: feedSelectionListViewController.view];
//animate the navigation bar, feed selection list, and this view controller's view to the right
[UIView animateWithDuration: LIST_SHOW_TRANSITION_TIME animations: ^{
self.view.frame = CGRectOffset(self.view.frame, offset, 0);
navigationController.navigationBar.frame = CGRectOffset(navigationController.navigationBar.frame, offset, 0);
feedSelectionListViewController.view.frame = CGRectOffset(feedSelectionListViewController.view.frame, offset, 0);
}];
}
這真的很混亂,而不是所有關於它的工作都是正確的。首先,當用戶離開並回到應用程序時,UINavigationBar似乎已將其重置爲框架。當通話狀態欄打開和關閉時也會發生這種情況。其次,右側視圖中的任何視圖都不會按照他們的意圖向右移動。我不知道這是爲什麼。
但是,如果我有
navigationController.view.frame = CGRectOffset(navigationController.view.frame, 200, 0);
更換動畫塊它工作正常。導航控制器當前顯示的視圖的子視圖會相應地移動,並且在應用程序恢復時所有內容都在正確的位置。但是,側邊欄視圖不會接收觸摸事件,現在由AppDelegate處理通過側邊欄進行的觸摸。我懷疑這是因爲UIView的框架有{-200,0}的起源,儘管我不能確定。
我不認爲我是理解的東西。這甚至是正確的方法嗎?我想不出有什麼其他的辦法可以做到這一點。無論如何,超級感謝提前任何指導或建議。
-matt
儘量使用您的解決方案,這是我的一位老師的項目(她喜歡我們學校的RSS閱讀器)。由於我是一個相當忙碌的學生,我喜歡藉口來處理應用程序。由於我最近沒有多少時間去玩UIKit的更高級用途,所以我想提高自己的技能並且自己實現它(我不會去拖,只是點擊),而且它真的這讓我不知道發生了什麼。 - 總之,我喜歡知道爲什麼事情不是隻接受它們。 – 2012-02-25 23:18:51
我添加了一個編輯,以更好地指導您實現自己的解決方案。 – pkluz 2012-02-25 23:23:08
我想我會研究創建自己的UIViewController,它實現UIViewController包含方法。 - 感謝您的指導。 - 但是,我仍然非常困惑,爲什麼我沒有做到。我真的很想知道爲什麼UINavigationBar回到原來的位置,爲什麼UIView沒有收到觸摸事件,爲什麼改變UIView的框架並沒有改變它的子視圖。這一切都很混亂。 – 2012-02-26 03:29:57