将UINavigationBar传递给多个UIViewControllers

时间:2013-08-18 06:56:26

标签: iphone ios uinavigationcontroller uinavigationbar

所以,目前,我正在尝试将相同的UINavigationBar传递给多个UIViewController

例如,假设我有UINavigationController,其视图为UIViewController的{​​{1}}。在自定义UIView的{​​{1}}内,我修改了UINavigationBar UIViewController的内容。

UIView

当用户按下UIViewcontroller中的按钮(不是指向navigationBar的项目)时,用户就会被推送到另一个titleview

UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(self.navigationController.navigationBar.frame.origin.x + 50, self.navigationController.navigationBar.frame.origin.y, self.navigationController.navigationBar.frame.size.width - 100, 44)];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
button1.frame = CGRectMake(35, titleView.frame.origin.y + 2, 40, 40);
[button1 setImage:[UIImage imageNamed:@"FacebookFriendRequestIcon.png"] forState:UIControlStateNormal];
[button1 addTarget:self action:@selector(FriendRequestsPopover:) forControlEvents:UIControlEventTouchUpInside];
[titleView addSubview:button1];
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
button2.frame = CGRectMake(80, titleView.frame.origin.y + 2, 40, 40);
[button2 setImage:[UIImage imageNamed:@"FacebookMessagesIcon.png"] forState:UIControlStateNormal];
[button2 addTarget:self action:@selector(MessagesPopover:) forControlEvents:UIControlEventTouchUpInside];
[titleView addSubview:button2];
UIButton *button3 = [UIButton buttonWithType:UIButtonTypeCustom];
button3.frame = CGRectMake(125, titleView.frame.origin.y + 2, 40, 40);
[button3 setImage:[UIImage imageNamed:@"FacebookNotificationsIcon.png"] forState:UIControlStateNormal];
[button3 addTarget:self action:@selector(NotificationsPopover:) forControlEvents:UIControlEventTouchUpInside];
[titleView addSubview:button3];

self.navigationItem.titleView = titleView;

UIViewController

因此,GeneralInfoViewController *generalInformationController = [[GeneralInfoViewController alloc] init]; [self.navigationController pushViewController:generalInformationController animated:YES]; 被子类化为UIViewController1(UINavigationController) pushes to UIViewController2(UINavigationController)。现在当推送发生时,我希望动画发生,但只有generalInformationController不能使用NavigationBar。

示例应用程序就像Facebook一样,导航栏的中间按钮(消息,朋友请求和通知)总是可见的,并且当视图控制器被推入堆栈时从不动画。

任何人对如何做到这一点都有任何想法?我想理论上的答案会很好但是编码的例子会更好:)

2 个答案:

答案 0 :(得分:0)

  

示例应用程序就像Facebook,Navigationbar's   中间按钮(消息,朋友请求和通知)是   当按下viewcontroller时,总是可以看到并且永远不会动画   在堆栈上。

这可能是Facebook应用程序不使用导航控制器的线索。我不知道它是否存在,但是编写自己的容器视图控制器可能会更容易,而不是试图强制UINavigationController以不符合设计的方式运行。

答案 1 :(得分:0)

如果您使用导航控制器进行推动和弹出,则无法确定您的唠叨栏位于其位置; 但你可以尝试一下:

newView.bounds = mainView.bounds; //newView can be nextViewController.view
newView.biunds.size.height=newView.biunds.size.height-self.navBar.bounds.size.height; //devide navBar height
newView.frame = CGRectMake(newView.frame.origin.x + 784, newView.frame.origin.y, newView.frame.size.width, newView.frame.size.height);
[mainView addSubview:newView];

/* Begin transition */
[UIView beginAnimations:@"Slide Left" context:oldView];
[UIView setAnimationDelegate:self];
[UIView setAnimationDelay:0.0f];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationDidStopSelector:@selector(slideInCompleted:finished:context:)];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
newView.frame = CGRectMake(0,0, newView.frame.size.width, newView.frame.size.height);
oldView.frame = CGRectMake(oldView.frame.origin.x - 784, oldView.frame.origin.y, oldView.frame.size.width, oldView.frame.size.height);
[UIView commitAnimations];

发表评论,为您的结果。