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