A. Requirements1. Similar to QQ, top or bottom of the window conversion navigation bar 2. Add content to each page
B.uitabbarcontroller1. Basic concept: (1) Content height iOS7 before content height: screen height-status bar height 44-bottom navigation bar height 49ios7 and after, content height is full screen 2. Using code creation Initialization (1) to create a Uitabbarcontrolleruitabbarcontroller use step
- Initialize Uitabbarcontroller
- Set the Rootviewcontroller for UIWindow to Uitabbarcontroller
- Depending on the case, add the corresponding number of sub-controllers by the Addchildviewcontroller method
(2) Add a sub-controller Uitabbarcontroller There are 2 ways to add a controller
- Adding a single child controller
-(void) Addchildviewcontroller: (Uiviewcontroller *) Childcontroller;
- Set up a sub-controller array
@property (nonatomic,copy) Nsarray *viewcontrollers; If the Uitabbarcontroller has n sub-controllers, then there will be N Uitabbarbutton inside Uitabbar as child controls if Uitabbarcontroller has 4 sub-controllers, then the structure of Uitabbar is roughly as shown Appdelegate:
1-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {2 //Override point for customization after application launch.3 4 //Set Window5Self.window =[[UIWindow alloc] init];6Self.window.frame =[[UIScreen mainscreen] bounds];7Self.window.backgroundColor =[Uicolor Graycolor];8 [Self.window makekeyandvisible];9 Ten One //set up a Uitabbarcontroller AUitabbarcontroller *tabbarcontroller =[[Uitabbarcontroller alloc] init]; -Self.window.rootViewController =Tabbarcontroller; - the //Adding a child controller -Uiviewcontroller *C1 =[[Uiviewcontroller alloc] init]; -C1.view.backgroundColor =[Uicolor Redcolor]; - //[Tabbarcontroller addchildviewcontroller:c1]; + -Uiviewcontroller *C2 =[[Uiviewcontroller alloc] init]; +C2.view.backgroundColor =[Uicolor Bluecolor]; A //[Tabbarcontroller ADDCHILDVIEWCONTROLLER:C2]; at -Uiviewcontroller *C3 =[[Uiviewcontroller alloc] init]; -C3.view.backgroundColor =[Uicolor Greencolor]; - -Tabbarcontroller.viewcontrollers =@[c1,c2,c3]; - in - returnYES; to}
(3) Set the navigation bar option style Uitabbarbutton What is displayed inside, determined by the Tabbaritem property of the corresponding sub-controller
Uitabbaritem has the following properties that affect the content of Uitabbarbutton
Title text
@property (nonatomic,copy) NSString *title;
Icon
@property (Nonatomic,retain) UIImage *image;
Icon When selected
@property (Nonatomic,retain) UIImage *selectedimage;
Reminder number @property (nonatomic,copy) NSString *badgevalue; Appdelegate:
1-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {2 //Override point for customization after application launch.3 4 //Set Window5Self.window =[[UIWindow alloc] init];6Self.window.frame =[[UIScreen mainscreen] bounds];7Self.window.backgroundColor =[Uicolor Graycolor];8 [Self.window makekeyandvisible];9 Ten One //set up a Uitabbarcontroller AUitabbarcontroller *tabbarcontroller =[[Uitabbarcontroller alloc] init]; -Self.window.rootViewController =Tabbarcontroller; - the //Adding a child controller -Uiviewcontroller *C1 =[[Uiviewcontroller alloc] init]; -C1.view.backgroundColor =[Uicolor Redcolor]; -C1.tabBarItem.title =@"Red"; + //[Tabbarcontroller addchildviewcontroller:c1]; - +Uiviewcontroller *C2 =[[Uiviewcontroller alloc] init]; AC2.view.backgroundColor =[Uicolor Bluecolor]; atC2.tabBarItem.title =@"Blue"; - //[Tabbarcontroller ADDCHILDVIEWCONTROLLER:C2]; - -Uiviewcontroller *C3 =[[Uiviewcontroller alloc] init]; -C3.view.backgroundColor =[Uicolor Greencolor]; -C3.tabBarItem.title =@"Green"; in -Tabbarcontroller.viewcontrollers =@[c1,c2,c3]; to + - returnYES; the}
3. Use storyboard to create initialization (1) drag into Uitabbarcontroller (2) drag into n Uiviewcontroller to use (3) to set the Uitabbarcontroller sub-controller in sequence (4) Set the Tabbaritem out of the sub-controller:
Note: Selected image is not set, the system will automatically program the original artwork blue as Selected image4. The life cycle of the sub-controller (1) The life cycle of a single sub-controller is the same as the normal controller life cycle
1- (void) Viewdidload {2 [Super Viewdidload];3NSLog (@"%@-Viewdidload", self.class);4 }5 6- (void) Viewwillappear: (BOOL) Animated {7 [Super viewwillappear:animated];8NSLog (@"%@-Viewwillappear", self.class);9 }Ten One- (void) Viewdidappear: (BOOL) Animated { A [Super viewdidappear:animated]; -NSLog (@"%@-Viewdidappear", self.class); - } the -- (void) Viewwilldisappear: (BOOL) Animated { - [Super viewwilldisappear:animated]; -NSLog (@"%@-Viewwilldisappear", self.class); + } - +- (void) Viewdiddisappear: (BOOL) Animated { A [Super viewdiddisappear:animated]; atNSLog (@"%@-Viewdiddisappear", self.class); - } - - -- (void) didreceivememorywarning { - [Super didreceivememorywarning]; inNSLog (@"%@-Didreceivememorywarning", self.class); - } to +- (void) Viewwillunload { - [Super Viewwillunload]; theNSLog (@"%@-Viewwillunload", self.class); * } $ Panax Notoginseng- (void) Viewdidunload { - [Super Viewdidunload]; theNSLog (@"%@-Viewdidunload", self.class); +}
(2) Life cycle of two sub-controller transitions A. The first child controller appears view
2014-12-27 21:11:44.338 uitabbarcontrollerbystoryboard[22567:590996] Oneviewcontroller-viewdidload
2014-12-27 21:11:44.340 uitabbarcontrollerbystoryboard[22567:590996] oneviewcontroller-viewwillappear
2014-12-27 21:11:44.407 uitabbarcontrollerbystoryboard[22567:590996] oneviewcontroller-viewdidappearB. Switching to a second controller view
2014-12-27 21:12:10.042 uitabbarcontrollerbystoryboard[22567:590996] Twoviewcontroller-viewdidload
2014-12-27 21:12:10.042 uitabbarcontrollerbystoryboard[22567:590996] Twoviewcontroller-viewwillappear
2014-12-27 21:12:10.042 uitabbarcontrollerbystoryboard[22567:590996] Oneviewcontroller-viewwilldisappear
2014-12-27 21:12:10.054 uitabbarcontrollerbystoryboard[22567:590996] oneviewcontroller-viewdiddisappear
2014-12-27 21:12:10.055 uitabbarcontrollerbystoryboard[22567:590996] twoviewcontroller-viewdidappear
C.app FrameWrap the previous Navigationcontroller before each sub-controller
[iOS base Control-6.12.1] QQ Menu Management Uitabbarcontroller Controller Management