Ios_20_ Weibo dock Follow-up switch

Source: Internet
Author: User

Final: Dock follows HOMEVC to switch




Requirements:

When you click on a line in the microblog list in Homevc,

Push to Statusdetail Weibo details controller, and the dock disappears together

When you click Statusdetail Weibo details controller The left back button on the top, and the dock is back with HOMEVC .


Homevc.m

Click on a microblog in the list to create a statusdetailviewcontroller, assign a value to its member status (data source), and enter the stack by navigation push-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) indexpath{    //Create a microblog body detail controller,    Statusdetailviewcontroller * DETAILVC = [[Statusdetailviewcontroller alloc] init];    Transfer Weibo data (for display) for the microblog body controller that is about to jump    statuslistcellframe *statuslistcellframe = _statuscellframes[indexpath.row] ;    Detailvc.status = Statuslistcellframe.status;    Jump past through the navigation controller    [Self.navigationcontroller PUSHVIEWCONTROLLER:DETAILVC animated:yes];}




As shown,

The view of the host controller (BEYONDVC) contains two parts:

1, upper navigation controller 2, dock below




The view of the upper navigation controller also includes two sections:

1, the upper navigation bar (when push, it always does not move)

2, lower root controller (HOMEVC) (animation toggle when push)







In order for the dock and navigation controller root control (HOMEVC) to slip together and slide back together,

The host controller (BEYONDVC) must be the proxy for the navigation controller,

enable it to monitor the push action Willshowviewcontroller and Didshowviewcontroller methods




In the following Willshowviewcontroller method,

First remove the dock from the host controller (BEYONDVC) and add it to the navigation controller's root control (HOMEVC)



the proxy method for the navigation controller Willshowviewcontroller


#pragma mark-the proxy method for the navigation controller//Screen width 320#define kwinwidth self.view.bounds.width//screen high 480#define kwinheight self.view.bounds. height//Top State Bar 20#define Kstatusbarheight 20//The purpose is to listen to the push action, when the new controller will enter the top of the stack, set the left button as the return arrow, set the right button back to home-(void) Navigationcontroller: (Uinavigationcontroller *) Navigationcontroller Willshowviewcontroller: (UIViewController *) Viewcontroller animated: (BOOL) animated{//Important ~ ~ ~//First get root controller Uiviewcontroller *ROOTVC = NAVIGATIONCONTROLLER.VIEWC        Ontrollers[0]; If the controller to be displayed (which will be pushed into the stack), not the bottom controller (root controller), it is necessary to set the left for the back button, the right home button if (viewcontroller! = ROOTVC) {//left return to the previous Controller ViewController.navigationItem.leftBarButtonItem = [Uibarbuttonitem barbuttonitemwithbgicon:@ "Navigationbar_ba                Ck.png "target:self Action: @selector (POPTOPREVIOUSVC)]; Back to the right of the home button, that is, back to the bottom of the stack controller (that is, from the details page back to the list page) ViewController.navigationItem.rightBarButtonItem = [Uibarbuttonitem barbuttonitem    withbgicon:@ "Navigationbar_home.png" target:self Action: @selector (BACKTOROOTVC)];                    1, first lengthen the navigation controller's view height to the height of the entire window-20 (because the dock disappears, the bottom will be more empty black space) NavigationController.view.frame = CGR                Ectmake (0, 20,320,480-20);                        2, first remove the dock from the view of the host controller (beyondviewcontroller) [_dock Removefromsuperview]; 3, in order to push the next controller, let the dock and the root controller to pan together, so, add the dock to the navigation controller's view of the root controller, and readjust the dock in the Homevc view of the Y value, notice that the navigation will not move, move the navigation root controller, The root Controller's origin (0 0) is: 20+ navigation bar Height 44//If the root controller is scrollable, be aware that the origin of Y is at the top of the tableview (after a certain distance is rolled down) if ([Rootvc.view IsK            Indofclass:[uiscrollview class]] {Uiscrollview * ScrollV = (Uiscrollview *) Rootvc.view; The Y-value inside the root controller of the navigation controller of the dock//because after scrolling, the upper-left corner of the Rootview is far away from the top _dock.frame =cgrectmake (0, Scrollv.contentof        Fset.y + 460-kdockheight, kdockheight); The Y value inside the root controller of the navigation controller of the else {//dock _dock.frame =cgrectmake (0, 480-20-2*kdockheight, +, Kdockheig        HT); }//4, and then add the dock to the navigation controller's root controller (the ROOTVC interface (the root controller of the navigation controller) to push the new VC, let the dock and navigation controller's root controller pan to the left side of the interface, and when you click the Back button, the dock will be back with ROOTVC [Rootvc.view Addsubview:_dock]; }}




in the following in the Didshowviewcontroller method,

First remove the dock from the navigation controller's root control (HOMEVC) and add it to the host controller (BEYONDVC)




the proxy method for the navigation controller Didshowviewcontroller

y = 20 of the navigation controller, height of the navigation controller = total Height-Dock height-20#define kcontentframe cgrectmake (0, Self.view.frame.size.width, Self.view . frame.size.height-kdockheight-20)//BEYONDVC host Controller, the dock y = total height-Dock Height # define Kdockframe cgrectmake (0, Self.view.fra Me.size.height-kdockheight, Self.view.frame.size.width, kdockheight)//The purpose is to monitor the push action and remove the dock from the navigation controller when the new controller is already displayed. And then re-display to the host controller-(void) Navigationcontroller: (Uinavigationcontroller *) Navigationcontroller Didshowviewcontroller: ( Uiviewcontroller *) Viewcontroller animated: (BOOL) animated{//The root controller of the bottom of the navigation first Uiviewcontroller *ROOTVC = Navigationco    Ntroller.viewcontrollers[0];   If the controller to be displayed is the root controller, re-place the dock if (Viewcontroller = = ROOTVC) {//Change the navigation controller view's frame//navigation Controller's y = 20, the height of the navigation controller =                Total height-dock height-navigationController.view.frame = kcontentframe;                Remove the dock first from the root controller ROOTVC on the bottom of the stack [_dock Removefromsuperview]; Add the dock to beyondviewcontroller,dock y = total height-Dock height _dock.frame = kdockframe;       [Self.view Addsubview:_dock]; }}




This allows the dock in the main controller to follow the root controller of the navigation controller, disappear together, and come back together .


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.