iOS Development Diary 13-profile NetEase News tab bar View Toggle (Addchildviewcontroller Property Introduction)

Source: Internet
Author: User

iOS Development Anatomy NetEase News tab bar View Toggle (Addchildviewcontroller Property Introduction)time 2014-06-25 21:45:21 csdn Blog Original http://blog.csdn.net/hmt20130412/article/details/34523235 ThemeNetEaseiOS Development

Originally just intended to introduce addchildviewcontroller this method, just today friends to change job interview asked NetEase news tab effect Implementation, combine it, with a small demo example introduction: (The specific explanation are written in the demo inside the note)

//Hmtmainviewcontroller.mUiscrollview//Created by HMT on 14-6-25.Copyright (c) 2014 Humingtao. All rights reserved.//#import "HMTMainViewController.h"#import "HMTFirstViewController.h"#import "HMTSecondViewController.h"#import "HMTThirdViewController.h" @Interface Hmtmainviewcontroller () <UIScrollViewDelegate> @property (nonatomic, strong) Hmtthirdviewcontroller * THIRDVC, @property (nonatomic, strong) Hmtfirstviewcontroller *FIRSTVC; @property (nonatomic, Strong) Hmtsecondviewcontroller *SECONDVC; @property (nonatomic, strong) Uiviewcontroller *CURRENTVC; @property (Nonatomic, Strong) Uiscrollview *headscrollview;Top scrolling View @property (nonatomic, strong) Nsarray *headarray; @end @implementation hmtmainviewcontroller-(ID) Initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *) nibbundleornil{ self = [super Initwithnibname:nibnameornil Bundle:nibbundleornil]; if (Self) {  Custom initialization} ReturnSelf;} -(void) viewdidload{[Super Viewdidload]; Do any additional setup after loading the view. Self.navigationItem.title = @"NetEase news demo";  Self.headarray = @[@"Headline", @"Entertainment", @"Sports", @"Finance", @"Technology", @"NBA", @"Mobile phone"]; /*** Automaticallyadjustsscrollviewinsets again by this attribute pit.* I "UI advanced" inside an article focused on it, you can go to see*/ Self.automaticallyadjustsscrollviewinsets = NO; Self.headscrollview = [[Uiscrollview alloc] Initwithframe:cgrectmake (0,64,320,40)]; Self.headScrollView.backgroundColor = [Uicolor Purplecolor]; Self.headScrollView.contentSize = Cgsizemake (560,0); Self.headScrollView.bounces = NO; self.headScrollView.pagingEnabled = YES;[Self.view Addsubview:Self.headscrollview]; for (int i =0; i < [Self.headarray Count]; i++) {   UIButton *button = [UIButton Buttonwithtype:uibuttontypesystem]; Button.frame = CGRectMake (0 + i*80,0,80,40); [Button settitle:[Self.headarray objectatindex:i] forstate:uicontrolstatenormal]; Button.tag = i +100; [Button AddTarget:Self action: @selector (didclickheadbuttonaction:) forcontrolevents:uicontroleventtouchupinside]; [Self.headscrollview Addsubview:button];  }  /*The new Apple API adds the Addchildviewcontroller method and wants us to call the [self Addchildviewcontroller:child] method while using Addsubview to set the sub The view corresponding Viewcontroller is also added to the current Viewcontroller management.For those who currently do not need to display the Subview, only through the Addchildviewcontroller to add Subviewcontroller, need to be displayed and then call the Transitionfromviewcontroller method. Add it to the underlying viewcontroller.The benefits of doing this: 1. There is no doubt that the logic in the page is more distinct. The corresponding view corresponds to the corresponding viewcontroller.2. When a sub view is not displayed, it will not be load, reducing the use of memory.3. When memory is tight, the view without load is released first, optimizing the program's memory release mechanism.*/  /*** In IOS5, the following new methods have been added to the Viewcontroller:* Addchildviewcontroller:* Removefromparentviewcontroller* TransitionFromViewController:toViewController:duration:options:animations:completion:* Willmovetoparentviewcontroller:* Didmovetoparentviewcontroller:*/ SELF.FIRSTVC = [[Hmtfirstviewcontroller alloc] init];[Self.firstVC.view Setframe:cgrectmake (0,104,320,464)];[Self ADDCHILDVIEWCONTROLLER:_FIRSTVC];  SELF.SECONDVC = [[Hmtsecondviewcontroller alloc] init];[Self.secondVC.view Setframe:cgrectmake (0,104,320,464)];  SELF.THIRDVC = [[Hmtthirdviewcontroller alloc] init];[Self.thirdVC.view Setframe:cgrectmake (0,104,320,464)];  Default, the first view (you will find that this one is used Addsubview)[Self.view Addsubview:Self.firstVC.view]; SELF.CURRENTVC =SELF.FIRSTVC;}-(void) Didclickheadbuttonaction: (UIButton *) button{ Click the button on the current page to jump directly out if ((SELF.CURRENTVC = =SELF.FIRSTVC && Button.tag = =100) | | (SELF.CURRENTVC = =SELF.SECONDVC && Button.tag = =101.)) {  Return}else{   Show 2, the rest, self-complement OH  Switch (Button.tag) {   Case100:   [Self Replacecontroller:SELF.CURRENTVC Newcontroller:SELF.FIRSTVC];    Break   Case101:   [Self Replacecontroller:SELF.CURRENTVC Newcontroller:SELF.SECONDVC];    Break   Case102:    //.......    Break   Case103:    //.......    Break   Case104:    //.......    Break   Case105:    //.......    Break   Case106:    //.......    Break    //.......   Default    Break }}}Toggle individual Label Contents-(void) Replacecontroller: (Uiviewcontroller *) Oldcontroller Newcontroller: (Uiviewcontroller *) newcontroller{ /*** Highlight It* TransitionFromViewController:toViewController:duration:options:animations:completion:* Fromviewcontroller The child View controller currently displayed in the parent view Controller* Toviewcontroller the pose diagram controller to be displayed* Duration Animation Time (this property, old friend O (∩_∩) o)* Options Animation effect (gradient, from bottom to top, etc., see API)* Animations animation during the conversion process* Completion Conversion complete*/ [Self Addchildviewcontroller:newcontroller];[Self Transitionfromviewcontroller:oldcontroller toviewcontroller:newcontroller Duration:2.0 options:uiviewanimationoptiontransitioncrossdissolve Animations:nil completion:^ (BOOL finished) {      if (finished) {       [Newcontroller Didmovetoparentviewcontroller:Self];  [Oldcontroller Willmovetoparentviewcontroller:nil];   [Oldcontroller removefromparentviewcontroller];< Span class= "indent" >   SELF.CURRENTVC = Newcontroller;      }else{   Span class= "indent" >     SELF.CURRENTVC = Oldcontroller;      }}];             

iOS Development journal 13-profile NetEase News tab bar View Toggle (Addchildviewcontroller property Introduction)

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.