带有中心面板的iOS应用程序,具有可展开的侧面板:JASidePanels
我正在使用JASidePanels与Facebook具有相同的布局,但有一些限制,我希望你能帮助我:
-
在中央视图控制器的导航控制器中添加一个右键
-
在不同的视图控制器中按下button之后,将中心视图更改为不同的视图
-
从左侧或右侧告诉中央视图控制器推视图
-
从左侧或右侧进入标签栏视图控制器内的视图
这里是我在MainAppDelegate中的实现:
/* tabbar views with their navigation controller */ SearchViewController *searchViewController = [[SearchViewController alloc] initWithNibName:@"SearchViewController" bundle:nil]; self.searchNavController = [[UINavigationController alloc] initWithRootViewController:searchViewController]; MainViewController *mainViewController = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil]; self.mainNavController = [[UINavigationController alloc] initWithRootViewController:mainViewController]; /* uiviewcontroller for our left side view */ SideMenuViewController *sideMenuViewController=[[SideMenuViewController alloc] initWithNibName:@"SideMenuViewController" bundle:nil]; /* the center view of the side panel */ self.mainSidePanelviewController = [[JASidePanelController alloc] init]; self.mainSidePanelviewController.shouldDelegateAutorotateToVisiblePanel = NO; /* set the properties of JASidePanel*/ self.mainSidePanelviewController.leftPanel = sideMenuViewController ; self.mainSidePanelviewController.centerPanel = self.mainNavController; [self.mainSidePanelviewController.centerPanel.navigationController setNavigationBarHidden:YES animated:YES]; NSArray *controllers = [NSArray arrayWithObjects: self.mainSidePanelviewController,self.searchNavController ,nil]; [self.tabController setViewControllers:controllers]; // the tab bar is our root view self.window.rootViewController = self.tabController; [self.window makeKeyAndVisible];
如果有一个更好的开源项目让我做我想做的事情,只要给我链接
只需添加您自己的button(例如在viewDidLoad中)并指定一个select器以显示右侧面板:
UIBarButtonItem *rightbutton = [UIBarButtonItem barItemWithImage:[UIImage imageNamed:@"rightIcon.png"] hightlightImage:[UIImage imageNamed:@"rightIcon.png"] target:self action:@selector(slideInRightHandView:)]; self.navigationItem.rightBarButtonItem = rightbutton;
-
导入接口头文件
#import“UIViewController + JASidePanel.h”
-
在ViewController中你要添加右键。 将下面的代码添加到viewDidLoad方法。
if (!self.navigationItem.rightBarButtonItem) { UIImage* image = [UIImage imageNamed:@"rightButtonImage.png"]; CGRect frameimg = CGRectMake(0, 0, image.size.width, image.size.height); UIButton *button = [[UIButton alloc] initWithFrame:frameimg]; [button setBackgroundImage:image forState:UIControlStateNormal]; [button addTarget:self.sidePanelController action:@selector(toggleRightPanel:) forControlEvents:UIControlEventTouchUpInside]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button]; }
您可以使用任何UIButton来创buildrightBarButtonItem。