iOS Learning Uinavigationcontroller

Source: Internet
Author: User
Tags set background

First, Uinavigationcontroller1, Uinavigationcontroller: Navigation controller, is one of the most commonly used multi-view controller in iOS, it is used to manage multiple view controllers. can be referred to as the controller of the management controller, the main management of hierarchical progressive relationship controller. 2, Uinavigationcontroller inherit from the Uiviewcontroller, in the way of the stack management of the control of the view controller, at least a managed view controller, this controller we call the navigation controller's root view controller.
    • Any class that inherits from Uiviewcontroller (polymorphic) can be used as the root controller.
3, the creation of Uinavigationcontroller
in APPDELEGATE.M  
    // Create a UIWindow object    Self.window = [[UIWindow alloc] Initwithframe:[uiscreen mainscreen].bounds];         // Set Background color    Self.window.backgroundColor = [Uicolor whitecolor];         // make window display     [Self.window makekeyandvisible];         // Create a View controller, assign a root controller to the window, set the navigation controller    Self.window.rootViewController = [[Uinavigationcontroller alloc] Initwithrootviewcontroller:[[rootviewcontroller ALLOC] [init]];
Second, Uinavigationbar 1. Overview
    • The settings on the Uinavigationbar (navigation bar) are mainly divided into two parts, one for various navigation parts (Uinavigationitem) on the navigation bar, and two for the navigation bar's own settings.
    • navigationbar--navigation Bar, iOS7 after the default is translucent, iOS7 before the default is opaque.
    • Navigationbar Vertical screen under the default height of 44, horizontal screen under the default height of 32.
    • After the iOS7, the Navigationbar background extends to StatusBar. The navigation bar height remains 44, but the display effect is 64.
    • Each view controller has a Navigationitem property. The left button, right button, caption, etc. set in Navigationitem are displayed on the Navigationbar as the controller is displayed.
2. Common Propertiesin the ROOTVIEWCONTROLLER.M
#import "RootViewController.h"@interfaceRootviewcontroller ()@end@implementationRootviewcontroller- (void) viewdidload {[Super viewdidload]; //Do any additional setup after loading the view.Self.view.backgroundColor =[Uicolor Browncolor]; //setting up the navigation controller[self initlayout];}//Initialize the layout (how to implement the layout)- (void) initlayout{//Display hidden properties of the navigation Controller (YES = = hidden, NO = = display)Self.navigationController.navigationBarHidden =NO; //Uinavigationbar (navigation bar, iOS7.0 after the navigation bar default has semitransparent properties)//sets whether the navigation bar turns on the translucent effect (which affects the self.subviews coordinate system, and when the translucent effect is on, self.view the upper-left corner of the screen as the origin of the coordinates, and the lower-left corner of the navigation bar is the origin of the coordinates when it is turned off)Self.navigationController.navigationBar.translucent =NO; //Modify the navigation bar color, the status bar color defaults to the same color as the navigation barSelf.navigationController.navigationBar.barTintColor =[Uicolor Graycolor]; //navigation bar Background colorSelf.navigationController.navigationBar.backgroundColor =[Uicolor Redcolor]; //set the title of the navigation bar//Self.title = @ "Root view"; //Navigationitem property, which is used to set child controlsSelf.navigationItem.title =@"Root View"; //left buttonSelf.navigationItem.leftBarButtonItem = [[Uibarbuttonitem alloc] Initwithtitle:@"left button"Style:uibarbuttonitemstyleplain target:self Action: @selector (Leftitemaciton:)]; //Right Button//a button//Self.navigationItem.rightBarButtonItem = [[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem: Uibarbuttonsystemitemcancel target:self Action: @selector (Rightitemclick:)];//    //Self.navigationItem.rightBarButtonItem = [[Uibarbuttonitem alloc] initwithimage:[uiimage imagenamed:@ "Next"]        Style:uibarbuttonitemstyleplain target:self Action: @selector (Rightitemclick:)]; //multiple buttons, auto sortUibarbuttonitem*item1 =[[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemcamera target:self action: @selector (        Rightitemclick:)]; Uibarbuttonitem*ITEM2 =[[Uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemreply target:self action: @selector (        Rightitemclick:)]; Self.navigationItem.rightBarButtonItems=@[item2, item1]; //set the color of the navigation elementSelf.navigationController.navigationBar.tintColor =[Uicolor Whitecolor]; //navigation bar StyleSelf.navigationController.navigationBar.barStyle =Uibarstyleblack; //Title ViewUisegmentedcontrol*segment = [[Uisegmentedcontrol alloc] initwithitems:@[@"Male Gods",@"Goddess",@"-1"]]; Segment.frame= CGRectMake (0,0, Max, -); Segment.selectedsegmentindex=0;        [Segment Addtarget:self Action: @selector (segmentaction:) forcontrolevents:uicontroleventvaluechanged]; Self.navigationItem.titleView=segment; UIView*view = [[UIView alloc] Initwithframe:cgrectmake (0,0, -, -)]; View.backgroundcolor=[Uicolor Lightgraycolor];    [Self.view Addsubview:view]; }//Implementing the Left button method- (void) Leftitemaciton: (Uibarbuttonitem *) sender{NSLog (@"Follow my left hand slow motion");}- (void) Segmentaction: (Uisegmentedcontrol *) sender{Switch(sender.selectedsegmentindex) { Case 0: Self.view.backgroundColor= [Uicolor colorwithred:1Green0Blue0Alpha1];  Break;  Case 1: Self.view.backgroundColor= [Uicolor colorwithred:0Green1Blue0Alpha1];  Break;  Case 2: Self.view.backgroundColor= [Uicolor colorwithred:0Green0Blue1Alpha1];  Break; default:             Break; }    }//Implementing the Right button method- (void) Rightitemclick: (Uibarbuttonitem *) sender{NSLog (@"Follow my right hand slow motion replay");}@end
3, the navigation controller left and right buttons in the English question (example cancle/cancel), in the project Setup->info->localization native development Region->china
third, page jump1. Working principle
    • The Uinavigationcontroller manages the switch of the controller through the stack, controls the stack and the stack to show the various view controllers.
    • The view of the top controller is always displayed in the Uinavigationcontroller Contentview.
    • The Viewcontrollers property is a mutable array (Nsmutablearray) that stores all the managed controllers in the stack, using AddObject to add a new view controller object to the end of the array when it is in the stack. Removelastobject removes the View controller object at the end of the array when it is out of the stack.
    • The Navigationcontroller property, the attributes in the parent class, and the controllers in each stack, can be obtained by this property to obtain their own Uinavigationcontroller object.
    • The characteristics of the stack: Advanced after-out, LIFO first.
2. Common Properties
 //  Implement Button method -(void ) Btnaction: (UIButton *) sender{ //   Create first Page object  firstviewcontroller *fvc = [[    Firstviewcontroller alloc] init];  //  launch new page with navigation controller   [Self.navigationcontroller PUSHVIEWCONTROLLER:FVC animated:yes];}  
-(void) Popbuttonaction: (UIButton *) sender{    //  return to previous view     [ Self.navigationcontroller Popviewcontrolleranimated:yes];       // returns the specified view    [Self.navigationcontroller poptoviewcontroller:self.navigationcontroller.viewcontrollers[0] Animated:yes];     // return to root view     [Self.navigationcontroller poptorootviewcontrolleranimated:yes];}
Iv. modal1, page switching mode comparison
    • Page switching methods are mainly divided into: launch (push) and modal (present).
    • Launched for a series of views between the jumps have a hierarchical progression relationship.
    • The modes used for separate function pages are not associated with the main business logic (login, Song play page, System album, call system function in the app).
2. Add transition animations (with default values)
-(void ) Modelbtnaction: (UIButton *)    sender{ //  Create a second page object     Showviewcontroller *svc = [[Showviewcontroller alloc] init];     //  Set the navigation controller to the second page  Uinavigationcontroller *SNVC = [[Uinavigationcontroller alloc]    INITWITHROOTVIEWCONTROLLER:SVC];     //  add modal animations     Svc.modaltransitionstyle = uimodaltransitionstylecoververtical;  //  modal jumps to the next page   [Self.navigationcontroller PRESENTVIEWCONTROLLER:SNVC animated:yes completion:nil];}  
-(void) Backbtnaction: (UIButton *) sender{    //  modal return to previous view     [self Dismissviewcontrolleranimated:yes Completion:nil];}
Effects of modal animations
uimodaltransitionstylepartialcurl Flip Mode launch // Uimodaltransitionstylefliphorizontal Horizontal rotation Introduction // uimodaltransitionstylecrossdissolve cross-fold dissolution method launched // Uimodaltransitionstylecoververtical Vertical Cover method launched

iOS Learning Uinavigationcontroller

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.