Animation hiding uitabbarcontroller and uinavigationcontroller
:
Source code:
Appdelegate. m
//// Appdelegate. M // hidetabbar /// copyright (c) 2014 y. x. all rights reserved. // # import "appdelegate. H "# import" rootviewcontroller. H "@ implementation appdelegate-(bool) Application :( uiapplication *) Application didfinishlaunchingwitexceptions :( nsdictionary *) launchoptions {self. window = [[uiwindow alloc] initwithframe: [[uiscreen mainscreen] bounds]; // override point for customization after application launch. uitabbarcontroller * tab = [[uitabbarcontroller alloc] init]; tab. viewcontrollers = @ [[rootviewcontroller new]; uitabbar * tabbar = tab. tabbar; uitabbaritem * tabbaritem = [tabbar. items objectatindex: 0]; tabbaritem. title = @ "youxianming"; nsdictionary * textdic =@{ nsfontattributename: [uifont fontwithname: @ "helveticaneue-thin" Size: Drawing f]}; [tabbaritem detail: uioffsetmake, -12.f)]; [tabbaritem settitletextattributes: textdic forstate: uicontrolstatenormal]; uinavigationcontroller * NC = [[uinavigationcontroller alloc] initwithrootviewcontroller: Tab]; self. window. rootviewcontroller = NC; self. window. backgroundcolor = [uicolor whitecolor]; [self. window makekeyandvisible]; return yes;} @ end
Rootviewcontroller. m
//// Rootviewcontroller. M // hidetabbar /// copyright (c) 2014 y. x. all rights reserved. // # import "rootviewcontroller. H "@ interface rootviewcontroller () @ property (nonatomic, assign) bool flag; @ end @ implementation rootviewcontroller-(void) viewdidload {[Super viewdidload]; self. view. layer. contents = (_ bridge ID) ([uiimage imagenamed: @ "back"]. cgimage); // Add a gesture uitapgesturerecognizer * tap = [uitapgest Urerecognizer alloc] initwithtarget: Self action: @ selector (event :)]; [self. View addgesturerecognizer: tap];}-(void) event :( uitapgesturerecognizer *) tap {if (! _ Flag) {[self hidetabbar: Self. tabbarcontroller];} else {[self showtabbar: Self. tabbarcontroller];} _ flag =! _ Flag;}-(void) hidetabbar :( uitabbarcontroller *) tabbarcontroller {// hide the navigation bar [self. navigationcontroller setnavigationbarhidden: Yes animated: Yes]; // hide tabbar [uiview animatewithduration: uinavigationcontrollerhideshowbarduration animations: ^ {for (uiview * view in tabbarcontroller. view. subviews) {If ([view iskindofclass: [uitabbar class]) {[view setframe: cgrectmake (view. frame. origin. x, view. frame. origin. Y + 50, view. frame. size. width, view. frame. size. height)];} else {[view setframe: cgrectmake (view. frame. origin. x, view. frame. origin. y, view. frame. size. width, view. frame. size. height + 50)] ;}}}] ;}- (void) showtabbar :( uitabbarcontroller *) tabbarcontroller {// display the navigation bar [self. navigationcontroller setnavigationbarhidden: No animated: Yes]; // display tabbar [uiview animatewithduration: uinavigationcontrollerhideshowbarduration animations: ^ {for (uiview * view in tabbarcontroller. view. subviews) {If ([view iskindofclass: [uitabbar class]) {[view setframe: cgrectmake (view. frame. origin. x, view. frame. origin. y-50, view. frame. size. width, view. frame. size. height)];} else {[view setframe: cgrectmake (view. frame. origin. x, view. frame. origin. y, view. frame. size. width, view. frame. size. height-50)] ;}}] ;}@ end
Core: