Ui03-viewcontroller View Jump:

Source: Internet
Author: User

/* ****** today task: final optimization of the login interface, package controls (2) Viewcontroller (3) MVC (4) For screen rotation, memory exception handling, (5) Container View Controller, four ways to use view switching

1. Optimization of the login interface,

(1) package design pattern, decorator mode, composite design mode, 23 design Patterns A custom control has multiple system controls inside it.

(1) Customize a view, based on the UI view, to include the system controls as. The properties in H,

(2) Override the initialization method in. m to write down the properties of the individual system controls, paying attention to the size distribution of the individual controls, as below,

Try to use System attributes to determine boundaries

-(Instancetype) initWithFrame: (CGRect) frame{

Self=[super Initwithframe:frame];

if (self) {

Initialize 2 properties

_lable=[[uilabel alloc]initwithframe:cgrectmake (0, 0, a, cgrectgetheight (Self.frame))];

Self.backgroundcolor=[uicolor Orangecolor];

[Self addsubview:_lable];

_field=[[uitextfield Alloc]initwithframe:cgrectmake (Cgrectgetmaxx (self.lable.frame) +20, Cgrectgetminy (_ Lable.frame), Cgrectgetwidth (self.frame)-cgrectgetwidth (_lable.frame) -20, Cgrectgetheight (Self.frame))];

_field.borderstyle=uitextborderstyleroundedrect;

_field.backgroundcolor=[uicolor Cyancolor];

[Self Addsubview:_field];

}

return self;

}

2.viewController View Controller,

(1) Reasons for the occurrence:

1) share the work of appdelegate. Module independence, a view controller equivalent to an interface

2) Gaonezu, low coupling.

3) Modular programming, easy to cooperate with the development.

(2) Sharing of work,

1) Control the size change of the view, layout, response events,

2) Detect and Process memory warnings

3) Detect and process the rotation of the screen

4) Switch the view

3. How to create a view controller,

(1) Create document Commad + N Firstviewcontroller:uiviewcontroller

(2) Inside the appdelegate, specify the view controller created for itself in the window root view Controller

[Requires the root view controller to be specified at 7, does not specify a crash exit]

Firstviewcontroller *fvc=[[firstviewcontroller Alloc]init];

SELF.WINDOW.ROOTVIEWCONTROLLER=FVC;

(3) Controller is the default comes with a view, the size is as large as the screen,

4. Mvc

(1) In the proxy file, the Rootviewcontroller of window is given to the custom Contrller (based on Uiviewcontrller). New contrller-Introduction Header file-initialization-assignment of four steps.

(2) Custom view (based on UIView), replaces the default view of Contrller: Introduce header file Custom view as Contrller property override Loadview (load parent view, initialize custom view, assign value)

(3) Create controls and methods on custom views:. h Create a control property,. m overrides the initialization method: Loads the parent view, defines the control's properties (self Setbutton) in the method that you create, and assigns values to the properties of the control.

(4) The response event of the button is added in the didload of the Controller, and the implementation of the response method is implemented below (jump).

5. Screen rotation

(1). screen rotation, not just check in the configuration file, the code should also be set,

Support left and right rotation,-(Nsuinteger) supportedinterfaceorientations {return uiinterfaceorientationmaskall; }

(2) The screen is about to enter the rotation of the call, after the size of rotation, the user interface to turn off the response,

-(void) Viewwilltransitiontosize: (cgsize) size withtransitioncoordinator: (id< uiviewcontrollertransitioncoordinator>) coordinator{

Self.view.userinteractionenabled=yes;

}

(2) This method is to support the direction of rotation, not the rotation of the phone, but the rotation of the screen, because the content of the screen and the mobile phone rotation is the opposite.

-(Nsuinteger) supportedinterfaceorientations

{return uiinterfaceorientationmaskall; }

This return is the direction of the screen content rotation.

(3)

-(void) layoutsubviews{

The direction of the current phone can be obtained according to this method

if ([UIApplication sharedapplication].statusbarorientation==uiinterfaceorientationlandscapeleft)

NSLog (@ "contrived");

}

6. Memory exception warning system is going to crash

Memory warning, this method is called when memory crashes.

When the memory is about to crash, do the work of data saving, save the data as a document, or put it in the database, prevent data loss.

-(void) didreceivememorywarning { [super didreceivememorywarning];}

8. View Jump:

(1) Response load View-(void) Denglu: (uibutton*) buu{

Zhuceviewcontroller *zhuce=[[zhuceviewcontroller Alloc]init];

[Self presentviewcontroller:zhuce animated:yes completion:nil];

}

(2)

Cancels the responder and returns to the initial interface.

-(void) Quxiao: (UIButton *) buuu{

[Self dismissviewcontrolleranimated:yes completion:nil];

}

Click anywhere to recycle the keyboard.

-(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) event

{

[Self.view Endediting:yes];

}

Ui03-viewcontroller View Jump:

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.