简体   繁体   English

将UINavigationBar传递给多个UIViewControllers

[英]Passing UINavigationBar to multiple UIViewControllers

So, at the moment, I am attempting to pass the same UINavigationBar to multiple UIViewController s. 因此,目前,我正在尝试将同一UINavigationBar传递给多个UIViewController

For example, say I have a UINavigationController whose view is a UIViewController 's UIView . 例如,假设我有一个UINavigationController其视图是UIViewControllerUIView Withinn the custom UIViewController 's UIView I modify the contents of the UINavigationBar's titleview . 在自定义UIViewControllerUIView我修改了UINavigationBar的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;

When a user presses a button within the UIViewcontroller (not referring to the navigationBar's items), the user is then pushed to another UIViewController : 当用户按下UIViewcontroller中的按钮(不引用navigationBar的项目)时,该用户随后被推到另一个UIViewController

GeneralInfoViewController *generalInformationController = [[GeneralInfoViewController alloc] init];
[self.navigationController pushViewController:generalInformationController animated:YES];

UIViewController1(UINavigationController) pushes to UIViewController2(UINavigationController)

So, the generalInformationController is subclassed as a UIViewController . 因此, generalInformationController被子类化为UIViewController Now when the push occurs, I would like an animation to occur, but only with the UIView 's not with the NavigationBar. 现在,当进行推送时,我希望出现动画,但是仅使用UIView而不是NavigationBar。

An example application would be like Facebook, the Navigationbar's middle buttons (messages, friend requests, and notifications) are ALWAYS visibile and never animate away when a viewcontroller is pushed onto the stack. 一个示例应用程序就像Facebook,导航栏的中间按钮(消息,好友请求和通知)始终可见,并且在将视图控制器推入堆栈时永远不会动起来。

Anyone have any ideas on how this is done? 任何人都对如何实现有任何想法? I guess a theoretical answer would be nice but a coding example would be nicer :) 我想理论上的答案会不错,但是编码示例会更好:)

An example application would be like Facebook, the Navigationbar's middle buttons (messages, friend requests, and notifications) are ALWAYS visibile and never animate away when a viewcontroller is pushed onto the stack. 一个示例应用程序就像Facebook,导航栏的中间按钮(消息,好友请求和通知)始终可见,并且在将视图控制器推入堆栈时永远不会动起来。

That might be a clue that the Facebook app doesn't use a navigation controller. 这可能是Facebook应用程序不使用导航控制器的线索。 I don't know if it does or doesn't, but it would probably be easier to write your own container view controller that does what you want than to try to force UINavigationController to behave in a way that it's not designed to. 我不知道它是否可以,但是编写自己的容器视图控制器来执行您想要的事情可能比尝试强制UINavigationController以非设计方式运行要容易得多。

If you use navigation controller for pushing and poping, you can't make, that your nag bar stay on his place; 如果使用导航控制器进行推入和弹出操作,则无法确保导航栏停留在他的位置; BUT you can try it: 但是您可以尝试:

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

Post comments, for your result. 发表评论,为您的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM