Knowledge Summary of navigation Controller

Source: Internet
Author: User

1. Function and introduction of navigation controller

The "note" Navigation Controller, a container view controller provided by the Uikit framework, is used to toggle views that have a clear hierarchical relationship. That is, the first-level view switches to the level two view, not the switch between the peer view.

The hierarchy of view controllers in the "note" Navigator, called the stack structure.

2. How to use the navigation controller to achieve a jump between interfaces

<1> display an interface that shows the navigation bar

Using the navigation controller

1. Create a navigation controller, RVC in the navigation controller

2. Navigation Controller as window root view Controller

Nav Bar Size: 320x44

Rootviewcontroller *RVC = [[Rootviewcontroller alloc] init];

Uinavigationcontroller *NC = [[Uinavigationcontroller alloc] INITWITHROOTVIEWCONTROLLER:RVC];

Self.window.rootViewController = NC;

<2> switch to another interface using the navigation controller

Secondviewcontroller *svc = [[Secondviewcontroller alloc] init];

[Self.navigationcontroller pushviewcontroller:svc Animated:yes];

<3> How to switch to the previous interface using code

Implementation switches to the previous interface

[Self.navigationcontroller Popviewcontrolleranimated:yes];

<4> How to switch from any view controller to the root view controller

Very common: The application of any interface back to the login interface, back to the main app interface

Returns the root view controller in the navigation controller

[Self.navigationcontroller Poptorootviewcontrolleranimated:yes];

<5> How to navigate the controller to switch to any view controller

How to switch to the second interface with a navigation controller

Viewcontrollers all view controllers in the store's navigation controller

Nsarray *viewcontrollers = self.navigationController.viewControllers;

[Self.navigationcontroller poptoviewcontroller:[viewcontrollers objectatindex:1] Animated:YES];

3. Settings for controls on the navigation bar

<1> set Title (text)

Self.title = @ "Main interface";

Control collection for navigation controllers

Self.navigationItem.title = @ "main";

Detail 1: The change is the title, the last one is valid

<2> Set Picture title

Title Position Display logo image

Detail 1:titleview high priority, overriding text title

Detail 2:titleview is UIView, meaning to set any control

Details 3:x and y ignore

Detail 4: Picture not showing (1) name (2) must be set size

Uiimageview *logoview = [[Uiimageview alloc] init];

Logoview.frame = CGRectMake (0, 0, 60, 35);

Logoview.image = [UIImage imagenamed:@ "Logo_title.png"];

Self.navigationItem.titleView = Logoview;

[Logoview release];

<3> Add text button to the left

<1> Create Text button

Uibarbuttonitem *leftitem = [[Uibarbuttonitem alloc] initwithtitle:@ "point Me" Style:uibarbuttonitemstyledone target:self Action: @selector (Navbuttonclick:)];

Self.navigationItem.leftBarButtonItem = Leftitem;

<4> Add system-style buttons to the left

<2> Create a system-style button

Uibarbuttonitem *leftitem = [[Uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemaction target: Self action: @selector (Navbuttonclick:)];

Self.navigationItem.leftBarButtonItem = Leftitem;

<5> Add a custom button to the left

Details: The picture does not show the problem, the size is not set

UIButton *leftbutton = [UIButton buttonwithtype:uibuttontypecustom];

Leftbutton.frame = CGRectMake (0, 0, 33, 30);

[LeftButton setbackgroundimage:[uiimage imagenamed:@ "Main_left_nav.png"] forstate:uicontrolstatenormal];

[LeftButton addtarget:self Action: @selector (Navcustombuttonclick:) forcontrolevents:uicontroleventtouchupinside];

Uibarbuttonitem *leftitem = [[Uibarbuttonitem alloc] Initwithcustomview:leftbutton];

Self.navigationItem.leftBarButtonItem = Leftitem;

<6> Add the returned button to the left of the next interface

Written in Mainviewcontroller

Detail 1: Shown on the next screen

Detail 2: Ignore event response methods for custom Buttonitem

Uibarbuttonitem *backitem = [[Uibarbuttonitem alloc] initwithtitle:@ "Back to main interface" Style:uibarbuttonitemstyledone target: Self action: @selector (Backbuttonclick:)];

Self.navigationItem.backBarButtonItem = Backitem;

[Backitem release];

4. Navigation bar settings (style, background image, color)

<1> set the style of the navigation bar

<1> styling (default and black)

<2> different versions will be different: Two enumeration values discarded using the

Details: The view moves up when the transparency is set

[Self.navigationController.navigationBar Setbarstyle:uibarstyleblack];

[Self.navigationController.navigationBar Settranslucent:yes];

<2> Color and Hue

<2> Navigation bar Color settings

Color???

Detail 1: Mixed color

Detail 2: Only appears when it is set to transparent

[Self.navigationController.navigationBar Setbackgroundcolor:[uicolor Redcolor];

Set tone

[Self.navigationController.navigationBar Settintcolor:[uicolor Redcolor];

<3> background Images

Uibarmetricsdefault indicates horizontal screen

Uibarmetricslandscapephone Vertical Screen

Details: Image format suitable for 320x44

[Self.navigationController.navigationBar setbackgroundimage:[uiimage imagenamed:@ "Header_bg.png"] forbarmetrics: Uibarmetricsdefault];

<4> Hide Navigation Bar

Hide Navigation Bar

[Self.navigationcontroller Setnavigationbarhidden:yes];

5. Use of toolbars (add buttons)

<1> How to display a tool bar

Detail: Navigation controller comes with navigation bar and tool bar

Toolbars are not displayed by default

[Self.navigationcontroller Settoolbarhidden:no];

<2> Add button on toolbar

Where the object should be Uibarbuttonitem

Details: Displayed from the left, no gaps in the buttons

Uibarbuttonitem *one = [[Uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitembookmarks target: Self action: @selector (Toolbuttonclick:)];

Uibarbuttonitem *two = [[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemcamera target:self Action: @selector (Toolbuttonclick:)];

Uibarbuttonitem *three = [[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemdone target:self Action: @selector (Toolbuttonclick:)];

The interval is also Uibarbuttonitem

Uibarbuttonitem *space = [[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemflexiblespace Target:nil Action:nil];

Self.toolbaritems = [Nsarray arraywithobjects:one,space,two,space,three,nil];

<3> specify the position of the button

Uibarbuttonitem *space = [[Uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemfixedspace target : Nil Action:nil];

Space.width = 60;

6. The interface of the navigation controller (single-pass value)

<1> forward Pass Value

Imagecategoryviewcontroller *ICVC = [[Imagecategoryviewcontroller alloc] init];

Icvc.username = @ "long ao tian";

Icvc.delegate = self;

[Self.navigationcontroller PUSHVIEWCONTROLLER:ICVC Animated:yes];

<2> Inverse value!!!

Ideas:

Think 1: The current View controller has no main pointer

<1> Current View Controller plus properties delegate

<2> switch to the current interface is set delegate

delegate, half of them are ID types.

Think: Can you send him a message

After sending delegate there is no way to respond to this message

<1> yourself to specify a protocol

<2> the other party abide by the agreement and implement the method in the Protocol

Details: Image making protocol, others obey

7. Extension: The effect of the transition between the fun interface

@ "Cube" @ "Movein" @ "reveal" @ "Fade" (default) @ "Pagecurl" @ "Pageuncurl" @ "Suckeffect" @ "Rippleeffect" @ "Oglflip"

Plus toggle effect, expand content

Quartzcore Implementing animations

1. Include Header files

2. Import library binaries

<1> creating objects

Catransition *animation = [catransition animation];

Set Animation type

@ "Cube" @ "Movein" @ "reveal" @ "Fade" (default) @ "Pagecurl" @ "Pageuncurl" @ "Suckeffect" @ "Rippleeffect" @ "Oglflip"

Animation.type = @ "Fade";

Set the direction of the animation

Animation.subtype = Kcatransitionfromtop;

Sets the animation time. 0.5 seconds

Animation.duration = 3;

Set the rhythm of the animation

Animation.timingfunction = [Camediatimingfunction functionwithname:kcamediatimingfunctioneaseout];

Animation adding to the navigation controller

[Self.navigationController.view.layer addanimation:animation Forkey:nil];

[Self.navigationcontroller PUSHVIEWCONTROLLER:ICVC Animated:yes];

8.//Set the return button color of Naviagtionbar

Self.navigationController.navigationBar.barTintColor = [Uicolor blackcolor]; Self.navigationController.navigationBar.tintColor = [Uicolor Whitecolor];

[Self.navigationController.navigationBar settitletextattributes:@{nsforegroundcolorattributename: [Uicolor Whitecolor]}];

Knowledge Summary of navigation Controller

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.