IOS UI03_UIViewController View Controller

Source: Internet
Author: User

IOS UI03_UIViewController View Controller

//

// AppDelegate. m

// UI03_UIViewController View Controller

//

// Created by dllo on 15/7/31.

// Copyright (c) 2015 zhozhicheng. All rights reserved.

//

 

# Import AppDelegate. h

# Import RootViewController. h

@ Interface AppDelegate ()

 

@ End

 

@ Implementation AppDelegate

-(Void) dealloc

{

[_ Window release];

[Super dealloc];

}

 

-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions {

Self. window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen] bounds];

// Override point for customization after application launch.

Self. window. backgroundColor = [UIColor whiteColor];

[Self. window makeKeyAndVisible];

[_ Window release];

// 1. Create a rootViewController object

RootViewController * rootVC = [[RootViewController alloc] init];

// 2. Set the Root View Controller for window

Self. window. rootViewController = rootVC;

[RootVC release];

 

Return YES;

}

 

-(Void) applicationWillResignActive :( UIApplication *) application {

// Sent when the application is about to move from active to inactive state. this can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games shocould use this method to pause the game.

}

 

-(Void) applicationDidEnterBackground :( UIApplication *) application {

// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

}

 

-(Void) applicationWillEnterForeground :( UIApplication *) application {

// Called as part of the transition from the background to the inactive state; here you can undo changes of the changes made on entering the background.

}

 

-(Void) applicationDidBecomeActive :( UIApplication *) application {

// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previusly in the background, optionally refresh the user interface.

}

 

-(Void) applicationWillTerminate :( UIApplication *) application {

// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground :.

}

 

@ End










//

// RootViewController. m

// UI03_UIViewController View Controller

//

// Created by dllo on 15/7/31.

// Copyright (c) 2015 zhozhicheng. All rights reserved.

//

 

# Import RootViewController. h

# Define HEIGHT self. view. frame. size. height

// # Import LTView. h

# Import SecondViewController. h

 

 

@ Interface RootViewController ()

@ Property (nonatomic, retain) NSMutableArray * arr;

 

@ End

 

@ Implementation RootViewController

// VC initialization method. This method is generally called by ourselves. We do not need to call it any more. Some containers, such as arrays and dictionaries, will be initialized.

-(Instancetype) initWithNibName :( NSString *) nibNameOrNil bundle :( NSBundle *) nibBundleOrNil

{

Self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil];

If (self ){

Self. arr = [NSMutableArray array];

 

}

NSLog (@ % s ,__ FUNCTION __);

Return self;

}

-(Void) loadView {

[Super loadView];

NSLog (@ % s ,__ FUNCTION __);

// Load self. view

}

# The pragma mark view will appear

-(Void) viewWillAppear :( BOOL) animated

{

 

[Super viewWillAppear: animated];

NSLog (@ % s ,__ FUNCTION __);

}

# Warning)

-(Void) viewDidAppear :( BOOL) animated

{

 

[Super viewDidAppear: animated];

NSLog (@ % s ,__ FUNCTION __);

}

# The pragma mark view is about to disappear

-(Void) viewWillDisappear :( BOOL) animated

{

[Super viewWillDisappear: animated];

NSLog (@ % s ,__ FUNCTION __);

}

# The pragma mark view has disappeared.

-(Void) viewDidDisappear :( BOOL) animated

{

[Super viewDidAppear: animated];

NSLog (@ % s ,__ FUNCTION __);

}

# Pragma mark if you want to write the method of the parent class, first use super to call the method of the parent class. This ensures that the original function remains unchanged, and then write the new function in the method.

 

 

 

 

 

-(Void) viewDidLoad {

[Super viewDidLoad];

// Do any additional setup after loading the view.

Self. view. backgroundColor = [UIColor cyanColor];

// NSLog (@ % s ,__ FUNCTION __);

// Create and lay a view in the viewdidload method.

// Lay three textfields

UITextField * textField1 = [[UITextField alloc] initWithFrame: CGRectMake (100,200,150, 40)];

TextField1.layer. borderWidth = 1;

TextField1.layer. cornerRadius = 10;

[Self. view addSubview: textField1];

TextField1.delegate = self;

[TextField1 release];

 

UITextField * textField2 = [[UITextField alloc] initWithFrame: CGRectMake (100,300,150, 40)];

TextField2.layer. borderWidth = 1;

TextField2.layer. cornerRadius = 10;

[Self. view addSubview: textField2];

TextField2.delegate = self;

[TextField2 release];

 

UITextField * textField3 = [[UITextField alloc] initWithFrame: CGRectMake (100,400,150, 40)];

TextField3.layer. borderWidth = 1;

TextField3.layer. cornerRadius = 10;

[Self. view addSubview: textField3];

TextField3.delegate = self;

[TextField3 release];

 

 

// Lay a button

UIButton * button = [UIButton buttonWithType: UIButtonTypeSystem];

Button. frame = CGRectMake (100,500,150, 40 );

[Button setTitle: @ next page forState: UIControlStateNormal];

[Self. view addSubview: button];

[Button addTarget: self action: @ selector (click :) forControlEvents: UIControlEventTouchUpInside];

Button. layer. borderWidth = 1;

Button. layer. cornerRadius = 10;

 

 

 

 

}

// Move the page up

-(BOOL) textFieldShouldBeginEditing :( UITextField *) textField

{

// The entire process is in self. view. The movement of the parent view will move all child views together, and the coordinates of the parent view will not change. Therefore, you can follow the judgment of the previous method.

// This method is triggered as long as the input box is activated.

If (textField. frame. origin. y> HEIGHT/2 ){

// Make a difference first

CGFloat height = textField. frame. origin. y-HEIGHT/2;

Self. view. center = CGPointMake (self. view. center. x, self. view. center. y-height );

}

Return YES;

}

// Wait until the compilation is complete and let him return to the original position

-(BOOL) textFieldShouldEndEditing :( UITextField *) textField

{

If (textField. frame. origin. y> HEIGHT/2 ){

CGFloat height = textField. frame. origin. y-HEIGHT/2;

Self. view. center = CGPointMake (self. view. center. x, self. view. center. y + height );

}

Return YES;

}

 

 

 

 

-(Void) click :( UIButton *) button

{

// Create a secondViewController object

SecondViewController * secondVC = [[SecondViewController alloc] init];

// Set the jump animation effect

[SecondVC setModalTransitionStyle: UIModalTransitionStyleCoverVertical];

// Jump

[Self presentViewController: secondVC animated: YES completion: ^ {

 

}];

// Memory Management

[SecondVC release];

 

// Random color

// [UIColor clearColor];

// Self. view. backgroundColor = [UIColor colorWithRed: arc4random () % 256/255 .0 green: arc4random () % 256/255 .0 blue: arc4random () % 256/255 .0 alpha: 1];

}

 

-(Void) didReceiveMemoryWarning {

[Super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

// Reclaim the keyboard

-(BOOL) textFieldShouldReturn :( UITextField *) textField

{

[TextField resignFirstResponder];

Return YES;

}

 

 

 

/*

# Pragma mark-Navigation

 

// In a storyboard-based application, you will often want to do a little preparation before navigation

-(Void) prepareForSegue :( UIStoryboardSegue *) segue sender :( id) sender {

// Get the new view controller using [segue destinationViewController].

// Pass the selected object to the new view controller.

}

*/

 

@ End















//

// SecondViewController. m

// UI03_UIViewController View Controller

//

// Created by dllo on 15/7/31.

// Copyright (c) 2015 zhozhicheng. All rights reserved.

//

 

# Import SecondViewController. h

 

 

@ Interface SecondViewController ()

 

@ End

 

@ Implementation SecondViewController

 

-(Void) viewDidLoad {

[Super viewDidLoad];

// Do any additional setup after loading the view.

Self. view. backgroundColor = [UIColor whiteColor];

 

 

UIButton * button = [UIButton buttonWithType: UIButtonTypeSystem];

Button. frame = CGRectMake (100,100,100, 30 );

Button. layer. borderWidth = 1;

Button. layer. cornerRadius = 10;

[Self. view addSubview: button];

[Button setTitle: @ return forState: UIControlStateNormal];

[Button addTarget: self action: @ selector (click :) forControlEvents: UIControlEventTouchUpInside];

 

 

 

 

 

 

 

 

}

// Click back to the previous page

-(Void) click :( UIButton *) button

{

[Self dismissViewControllerAnimated: YES completion: ^ {

 

}];

}

 

 

 

 

 

-(Void) didReceiveMemoryWarning {

[Super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

 

/*

# Pragma mark-Navigation

 

// In a storyboard-based application, you will often want to do a little preparation before navigation

-(Void) prepareForSegue :( UIStoryboardSegue *) segue sender :( id) sender {

// Get the new view controller using [segue destinationViewController].

// Pass the selected object to the new view controller.

}

*/

 

@ End



 

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.