Animation hiding uitabbarcontroller and uinavigationcontroller

Source: Internet
Author: User

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:

 

 

 

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.