View controller and Navigation mode one (modal view, tiled navigation)

Source: Internet
Author: User

Types of view Controllers

    • Uiviewcontroller. Navigation for customizing the View controller. For example, for two interface jumps, we can use one uiviewcontroller to control the other two uiviewcontroller.
    • Uinavigationcontroller. Navigation controller, which is used in conjunction with Uitableviewcontroller to build a tree-shaped navigation pattern.
    • Uitabbarcontroller. tab bar Controller for building tree label navigation mode.
    • Uipageviewcontroller. The controller that renders the ebook navigation style
    • Uisplotviewcontroller. The screen can be divided into several pieces of the view controller, mainly for the ipad screen design.
    • Uipopovercontroller. A controller that renders a "bubble" style view, designed primarily for the ipad screen.

Navigation mode:

    • Tile Navigation Mode: Content is not hierarchical, the content of the display is placed on a home screen, using a split-screen or paging controller to navigate, can be left or right to swipe the screen to view content. The weather app that comes with IPad touch, which uses a split-screen navigation.
    • Tag Navigation mode: The content is divided into several function modules, each function module has no relationship. Through the label management of each function module, click on the label can switch function module. The IPod touch self-guided clock app, which uses the tag navigation mode.
    • Tree structure Navigation mode: Content is hierarchical, from top to bottom subdivision or has the category contains, and so on, IPod touch in the use of the mail application, he uses the tree structure navigation mode

Modal View:

In the navigation process, it is sometimes necessary to abandon the main task to do other secondary tasks, and then return to the main task, this "secondary task" is done in the modal view. By default, modal views slide out from the bottom of the screen. When finished, you need to close the modal view, if you do not close, you can not do anything else, this is the meaning of modal, it has to respond to the meaning of processing. Therefore, there must be a "close" or "Finish" button in the modal view, with the root cause of iOS having only one home key. Andrioid and window phones do not experience these problems, as they can be returned by the back key when the above conditions are encountered in both systems.

In the Uiviewcontroller class, there are two main methods:

Presentmodalviewcontroller:animated: Render modal view

Dismissviewcontrolleranimated:completion: Close Modal view

Rendering and closing of modal views:

-(Ibaction) Regonclick: (ID) Sender {

Uistoryboard *mainstoryboard = [Uistoryboard storyboardwithname:@ "Main" bundle:nil];

Uiviewcontroller *registerviewcontroller = [Mainstoryboard instantiateviewcontrollerwithidentifier:@] Registerviewcontroller "];

Registerviewcontroller.modaltransitionstyle = uimodaltransitionstylecoververtical;

[Self Presentviewcontroller:registerviewcontroller animated:yes completion:^{

NSLog (@ "Present Modal View");

}];

}

The Modaltransitionstyle property is provided by the Uiviewcontroller class for animating the rendering and closing of modal views, defined by constants in the Uimodaltransitionstyle enumeration.

typedef ns_enum (Nsinteger, Uimodaltransitionstyle) {

Uimodaltransitionstylecoververtical = 0,//is rendered in the vertical direction from the bottom upward, and turned back from left to right when closed

uimodaltransitionstylefliphorizontal,//horizontal Flip, rendering is flipped from right to left, turning back from left to right

uimodaltransitionstylecrossdissolve,//Two views Cross fade

Uimodaltransitionstylepartialcurl,//The modal view rolls up a corner page when rendered, and the modal view turns back when it is closed.

};

-(Ibaction) Done: (ID) send{

[Self Dismissviewcontrolleranimated:yes completion:^{

NSLog (@ "Modal View done");

}];

}

Tile navigation

The flattening information means that there is no subordinate relationship between the information, such as Beijing, Shanghai and Harbin, and the relationship between Harbin City and Heilongjiang province is subordinate level. Application scenario: IPod Touch comes with weather app, ipad ibook ebook app

1. Split-screen navigation

Based on the split-screen navigation is the main implementation of the tiled navigation mode, mainly related to the control has split-screen control (Uipagecontrol) and scrolling view (ScrollView), where the sub-screen control is the iOS standard control. There are two kinds of gestures based on the split-screen navigation, one is the left (top) or the right (top) of the click Dot to realize the flip screen, and the other is to swipe the screen by hand. The total number of screens should be limited to 20, and more than 20 small point splitter controls will overflow. In fact, it is not convenient to use a tiled navigation mode based on split-screen navigation when an application is over 10 screens.

Instance:

@interface viewcontroller:uiviewcontroller<uiscrollviewdelegate>

@property (strong,nonatomic) UIView *page1;

@property (strong,nonatomic) UIView *page2;

@property (strong,nonatomic) UIView *page3;

@property (Weak, nonatomic) Iboutlet Uiscrollview *scrollview;

@property (Weak, nonatomic) Iboutlet Uipagecontrol *pagecontrol;

-(Ibaction) Changpage: (ID) sender;

#import "ViewController.h"

@interface Viewcontroller ()

@end

@implementation Viewcontroller

-(void) Viewdidload {

[Super Viewdidload];

Additional setup after loading the view, typically from a nib.

Self.scrollView.contentSize = Cgsizemake (self.view.frame.size.width*3, self.scrollView.frame.size.height);

Self.scrollView.frame = Self.view.frame;

Uistoryboard *mainstoryboard = [Uistoryboard storyboardwithname:@ "Main" bundle:nil];

Uiviewcontroller *page1viewcontroller = [Mainstoryboard instantiateviewcontrollerwithidentifier:@ "Page1"];

Self.page1 = Page1viewcontroller.view;

Self.page1.frame = CGRectMake (0.0f, 0.0f, 320.0f, 420.0f);

Uiviewcontroller *page2viewcontroller = [Mainstoryboard instantiateviewcontrollerwithidentifier:@ "Page2"];

Self.page2 = Page2viewcontroller.view;

Self.page2.frame = CGRectMake (320.0f, 0.0f, 320.0f, 420.0f);

Uiviewcontroller *page3viewcontroller = [Mainstoryboard instantiateviewcontrollerwithidentifier:@ "Page3"];

Self.page3 = Page3viewcontroller.view;

Self.page3.frame = CGRectMake (2*320.0f, 0.0f, 320.0f, 420.0f);

Self.scrollView.delegate = self;

[Self.scrollview AddSubview:self.page1];

[Self.scrollview AddSubview:self.page2];

[Self.scrollview AddSubview:self.page3];

}

-(void) Scrollviewdidscroll: (Uiscrollview *) ScrollView

{

Cgpoint offset = Scrollview.contentoffset;

Self.pageControl.currentPage = offset.x/320;

}

-(Ibaction) Changpage: (ID) Sender {

[UIView animatewithduration:0.3f animations:^{

int whichpage = Self.pageControl.currentPage;

Self.scrollView.contentOffset = Cgpointmake (320.0f*whichpage, 0.0f);

}];

}

-(void) didreceivememorywarning {

[Super didreceivememorywarning];

Dispose of any resources the can be recreated.

}

@end

2. Paging Navigation

Paging View Controller (Uipageviewcontroller) to build apps that resemble ebook effects.

The paging controller needs to be placed in a parent view controller, with a child view controller under the paging controller, one page for each child view controller

The classes and protocols that need to be used are uipageviewcontrollerdatesource protocols, uipageviewcontrollerdelegate protocols, and Uipageviewcontroller classes, Where the Uipageviewcontroller class does not have a corresponding view class.

@interface viewcontroller:uiviewcontroller<uipageviewcontrollerdatasource,uipageviewcontrollerdelegate>

{

int pageIndex;

}

@property (strong,nonatomic) Uipageviewcontroller *pageviewcontroller;

@end

#import "ViewController.h"

@interface Viewcontroller ()

@end

@implementation Viewcontroller

-(void) Viewdidload {

[Super Viewdidload];

Self.view.frame = CGRectMake (0.0f, 0.0f, 320.0f, 440.0f);

Self.pageviewcontroller = [[Uipageviewcontroller alloc]initwithtransitionstyle: Uipageviewcontrollertransitionstylepagecurl navigationorientation: Uipageviewcontrollernavigationorientationhorizontal Options:nil];

Self.pageViewController.delegate = self;

Self.pageViewController.dataSource = self;

Uistoryboard *mainstorybord = [Uistoryboard storyboardwithname:@ "Main" bundle:nil];

Uiviewcontroller *page1viewcontroller = [Mainstorybord instantiateviewcontrollerwithidentifier:@ "Page1"];

Nsarray *viewcontrollers = @[page1viewcontroller];

[Self.pageviewcontroller setviewcontrollers:viewcontrollers Direction: Uipageviewcontrollernavigationdirectionforward Animated:yes Completion:null];

[Self.view AddSubview:self.pageViewController.view];

PageIndex = 0;

}

/*

InitWithTransitionStyle:navigationOrientation:options: Constructs a method for creating an Uipageviewcontroller instance, Initwithtransitionstyle used to set the style of page flipping:

Uipageviewcontrollertransitionstylepagecurl---book effect style

Uipageviewcontrollertransitionstylescroll----sliding screen effect style

Navigationorientation Setting page flipping direction

uipageviewcontrollernavigationorientationhorizontal--Horizontal Direction

uipageviewcontrollernavigationorientationvertical--Vertical Direction

*/

-(void) didreceivememorywarning {

[Super didreceivememorywarning];

Dispose of any resources the can be recreated.

}

#pragma mark-uipageviewcontrollerdatasource

Returns the view controller before the current view controller for display on the previous page

-(Uiviewcontroller *) Pageviewcontroller: (Uipageviewcontroller *) Pageviewcontroller Viewcontrollerbeforeviewcontroller: (Uiviewcontroller *) Viewcontroller

{

pageindex--;

if (PageIndex < 0) {

PageIndex = 0;

return nil;

}

Uistoryboard *mainstorybord = [Uistoryboard storyboardwithname:@ "Main" bundle:nil];

NSString *pageid = [NSString stringwithformat:@ "page%d", pageindex+1];

Uiviewcontroller *pvcontroller = [Mainstorybord Instantiateviewcontrollerwithidentifier:pageid];

return pvcontroller;

}

Returns the view controller after the current view controller for display on the next page

-(Uiviewcontroller *) Pageviewcontroller: (Uipageviewcontroller *) Pageviewcontroller Viewcontrollerafterviewcontroller: (Uiviewcontroller *) Viewcontroller

{

pageindex++;

if (PageIndex > 2) {

PageIndex = 2;

return nil;

}

Uistoryboard *mainstorybord = [Uistoryboard storyboardwithname:@ "Main" bundle:nil];

NSString *pageid = [NSString stringwithformat:@ "page%d", pageindex+1];

Uiviewcontroller *pvcontroller = [Mainstorybord Instantiateviewcontrollerwithidentifier:pageid];

return pvcontroller;

}

#pragma mark-uipageviewcontrollerdelegate

/*

The most important way to uipageviewcontrollerdelegate a trust agreement is to pageviewcontroller:spinelocationforinterfaceorientation: It sets the spine position and initializes the first page based on the direction of the screen rotation. Uipageviewcontroller, there are two commonly used properties: two-sided display (doublesided) and spine position (spinelocation). The spine position is a read-only property and must be set by the proxy return value

*/

-(Uipageviewcontrollerspinelocation) Pageviewcontroller: (Uipageviewcontroller *) Pageviewcontroller Spinelocationforinterfaceorientation: (uiinterfaceorientation) orientation

{

Uistoryboard *mainstorybord = [Uistoryboard storyboardwithname:@ "Main" bundle:nil];

Uiviewcontroller *page1viewcontroller = [Mainstorybord instantiateviewcontrollerwithidentifier:@ "Page1"];

Uiviewcontroller *page2viewcontroller = [Mainstorybord instantiateviewcontrollerwithidentifier:@ "Page2"];

if (orientation = = Uiinterfaceorientationlandscapeleft | | orientation = = uiinterfaceorientationlandscaperight) {

Nsarray *viewcontrollers = @[page1viewcontroller,page2viewcontroller];

[Self.pageviewcontroller setviewcontrollers:viewcontrollers Direction: Uipageviewcontrollernavigationdirectionforward Animated:yes Completion:null];

self.pageViewController.doubleSided = NO;

return uipageviewcontrollerspinelocationmid;

}

Nsarray *viewcontrollers = @[page1viewcontroller];

[Self.pageviewcontroller setviewcontrollers:viewcontrollers Direction: Uipageviewcontrollernavigationdirectionforward Animated:yes Completion:null];

self.pageViewController.doubleSided = NO;

return uipageviewcontrollerspinelocationmin;

}

/*

typedef ns_enum (Nsinteger, uipageviewcontrollerspinelocation) {

Uipageviewcontrollerspinelocationnone = 0,//

Uipageviewcontrollerspinelocationmin = 1,//Defines the position of the spine at the far left (or top) of the book, and the book is flipped from right to left (or from top to bottom)

Uipageviewcontrollerspinelocationmid = 2,//Defines the position of the spine in the middle of the book, usually displayed in a horizontal screen, divided into two pages.

Uipageviewcontrollerspinelocationmax = 3//define the position of the spine at the far right (or bottom) of the book, the book is flipped from left to right (or from bottom to top)

};

*/

@end

View controller and Navigation mode one (modal view, tiled navigation)

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.