[英]Passing UINavigationBar to multiple UIViewControllers
因此,目前,我正在嘗試將同一UINavigationBar
傳遞給多個UIViewController
。
例如,假設我有一個UINavigationController
其視圖是UIViewController
的UIView
。 在自定義UIViewController
的UIView
我修改了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;
當用戶按下UIViewcontroller中的按鈕(不引用navigationBar的項目)時,該用戶隨后被推到另一個UIViewController
:
GeneralInfoViewController *generalInformationController = [[GeneralInfoViewController alloc] init];
[self.navigationController pushViewController:generalInformationController animated:YES];
UIViewController1(UINavigationController) pushes to UIViewController2(UINavigationController)
因此, generalInformationController
被子類化為UIViewController
。 現在,當進行推送時,我希望出現動畫,但是僅使用UIView
而不是NavigationBar。
一個示例應用程序就像Facebook,導航欄的中間按鈕(消息,好友請求和通知)始終可見,並且在將視圖控制器推入堆棧時永遠不會動起來。
任何人都對如何實現有任何想法? 我想理論上的答案會不錯,但是編碼示例會更好:)
一個示例應用程序就像Facebook,導航欄的中間按鈕(消息,好友請求和通知)始終可見,並且在將視圖控制器推入堆棧時永遠不會動起來。
這可能是Facebook應用程序不使用導航控制器的線索。 我不知道它是否可以,但是編寫自己的容器視圖控制器來執行您想要的事情可能比嘗試強制UINavigationController以非設計方式運行要容易得多。
如果使用導航控制器進行推入和彈出操作,則無法確保導航欄停留在他的位置; 但是您可以嘗試:
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];
發表評論,為您的結果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.