Custom Uitabbarcontroller Controller

Source: Internet
Author: User

Custom Uitabbarcontroller Controller

This is the basic principle of custom uitabbarcontroller, without functional encapsulation.

Effect:

Source Address:

Https://github.com/YouXianMing/Custom-TabbarController-Verson-One/tree/master

Source:

////VIEWCONTROLLER.M//Tabbarcontroller////Created by Xianmingyou on 15/4/15.//Copyright (c) 2015 xianmingyou. All rights reserved.//#import "ViewController.h"#import "FirstViewController.h"#import "SecondViewController.h"#import "uibutton+demouse.h"typedefenum: Nsuinteger { First=0x12, SECOND, Back_view,} Ebuttonflag;@interfaceViewcontroller () @property (nonatomic, strong) Firstviewcontroller*First ; @property (nonatomic, strong) Secondviewcontroller*Second, @property (nonatomic, strong) Uiviewcontroller*Current ;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; Self.view.backgroundColor=[Uicolor Whitecolor]; //Initialize the first controllerSelf.first = [FirstviewcontrollerNew];        [Self addChildViewController:self.first]; //Initialize a second controllerSelf.second = [SecondviewcontrollerNew];        [Self addChildViewController:self.second]; //load the view of the first controller[Self.first didmovetoparentviewcontroller:self];        [Self.view AddSubview:self.first.view]; //Simple storage of the current controllerSelf.current =Self.first; //Create a button[self createbuttons];}- (void) createbuttons {UIView*backview = [[UIView alloc] Initwithframe:cgrectmake (0, $, the, the)]; Backview.tag=Back_view;        [Self.view Addsubview:backview]; //Controller 1 Button[UIButton Createbuttonwithframe:cgrectmake (Ten,0,145, the) Withtag:first Withtitle:@" First"Withfont:nil addtarget:self Action: @se        Lector (buttonevent:) Haveborder:yes Insertinview:backview]; //Controller 2 Button[UIButton Createbuttonwithframe:cgrectmake (Ten+155,0,145, the) Withtag:second Withtitle:@"Second"Withfont:nil addtarget:self Action: @se Lector (buttonevent:) Haveborder:yes Insertinview:backview];}- (void) Buttonevent: (UIButton *) button {if(Button.tag = =First ) {                //This sentence must be added (otherwise click two times will be an error)        if([self.current IsEqual:self.first]) {return; }                //controller Transitions[Self transitionFromViewController:self.current toViewController:self.first Duration:0Options:uiviewanimationoptiontransitionnone Animatio NS:^{} completion:^(BOOL finished) {self.current=Self.first; //Set the button to the front[Self.view Bringsubviewtofront:[self.view Viewwithtag:back_view];            }]; } Else if(Button.tag = =SECOND) {                //This sentence must be added (otherwise click two times will be an error)        if([self.current IsEqual:self.second]) {return; }                //controller Transitions[Self transitionFromViewController:self.current toViewController:self.second Duration:0Options:uiviewanimationoptiontransitionnone Animatio NS:^{} completion:^(BOOL finished) {self.current=Self.second; //Set the button to the front[Self.view Bringsubviewtofront:[self.view Viewwithtag:back_view];            }]; }    }@end

Custom Uitabbarcontroller Controller

Related Article

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.