您的位置:首页 > 产品设计 > UI/UE

UIViewController

2015-12-24 14:35 615 查看
/***********************************************************************************/

#import "AppDelegate.h"

#import "RootViewController.h"

@interface
AppDelegate ()

@end

@implementation AppDelegate

-(void)dealloc

{

[_window release];

[super dealloc];

}

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

// Override point for customization after application launch.

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

// self.window.backgroundColor =[UIColor redColor];

self.window.backgroundColor
=[[UIColor
alloc]
initWithPatternImage:[UIImage
imageNamed:@"/Users/dllo/Desktop/UI/UI03_UIViewController/UI03_UIViewController/sdfsdf.jpg"]];

[self.window
makeKeyAndVisible];

[_window release];

///Xcode 7.0之后,所有的工程必须指定跟视图控制器,所以我们创建了一个ViewController的子类,然后把这个子类创建的对象指定为根视图控制器

///UIViewController这个类不能向button一样直接去使用,如果要用只能创建他的子类去使用

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

NSLog(@"%s",__FUNCTION__);

self.window.rootViewController =rooVc;

[rooVc release];

return
YES;

}

/////////////////////////////////////

#import "RootViewController.h"

#import "SecondViewControlle.h"

@interface
RootViewController ()

@property(nonatomic,retain)NSMutableArray *arr;

@property(nonatomic,retain)NSMutableDictionary *dic;

@end

@implementation RootViewController

//1.这个方法系统会自己调用,是他自己的初始化方法,一般在这个方法里对一些容器的属性进行初始化使用

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

{

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

if (self)

{

NSLog(@"%s",__FUNCTION__);

///容器属性在使用之前必须要进行初始化方法

self.arr =[NSMutableArray
array];

}

return
self;

}

-(void)loadView

{

[super loadView];

NSLog(@"%s",__FUNCTION__);

//2.如果重写父类的方法,如果要保证原功能不变,需要通过关键字super去调用父类的方法,这样父类的方法就会实现对应的功能,只需要在子类的放发写额外功能即可

//
作用就是对self.view进行加载

}

-(void)viewWillAppear:(BOOL)animated

{

[super viewWillAppear:animated];

NSLog(@"%s",__FUNCTION__);

// 4.执行到这个方法的时候,viewdidlod方法已经执行结束,视图已经创建好了,将要出现在屏幕上

}

-(void)viewDidAppear:(BOOL)animated

{

[super viewDidAppear:animated];

NSLog(@"%s",__FUNCTION__);

}

-(void)viewWillDisappear:(BOOL)animated

{

[super viewWillDisappear:animated];

NSLog(@"%s",__FUNCTION__);

}

-(void)viewDidDisappear:(BOOL)animated

{

[super viewWillDisappear:animated];

NSLog(@"%s",__FUNCTION__);

}

- (void)viewDidLoad {

[super
viewDidLoad];

// Do any additional setup after loading the view.

//3.执行到这个方法的时候.self.view已经加载好了,我们可以再放这里进行试图的创建,然后把师徒放到self.view上区显示

NSLog(@"%s",__FUNCTION__);

/// 视图控制器会自动创建一个透明的view,一般来讲需要先给self.view设置一个白色的背景色

/// 视图设置器也是以后最常用的,一般代码都在试图控制器内

// self.view.backgroundColor =[UIColor yellowColor];

self.view.backgroundColor
=[[UIColor
alloc]
initWithPatternImage:[UIImage
imageNamed:@"/Users/dllo/Desktop/UI/UI03_UIViewController/UI03_UIViewController/sdfsdf.jpg"]];

// UIButton *button =[UIButton buttonWithType:UIButtonTypeSystem];

// button.frame =CGRectMake(100, 100, 150, 50);

// button.backgroundColor =[UIColor redColor];

// [self.view addSubview:button];

// //标题
弧度 边框绑定一个点击方法

// [button setTitle:@"开始" forState:UIControlStateNormal];

// button.layer.borderWidth =1;

// button.layer.cornerRadius =25;

// [button addTarget:self action:@selector(cile:) forControlEvents:UIControlEventTouchUpInside];

UIButton *button =[UIButton
buttonWithType:UIButtonTypeSystem];

button.frame=CGRectMake(0,
0, 2,2 );

button.backgroundColor =[UIColor
whiteColor];

button.layer.borderWidth =1;

button.layer.cornerRadius=25;

[self.view
addSubview:button];

[button setTitle:@"开始"
forState:UIControlStateNormal];

[button addTarget:self
action:@selector(cile:)
forControlEvents:UIControlEventTouchUpInside];

}

-(void)cile:(UIButton *)button

{

///模态跳转

/// 1.先创建一个下一个对象

SecondViewControlle *secVc =[[SecondViewControlle
alloc]
init];

/// 2.设置跳转的动画效果

[secVc setModalTransitionStyle:
UIModalTransitionStyleFlipHorizontal];

///3.跳转

[self
presentViewController:secVc animated:YES
completion:^{

}];

/// 4.内存

[secVc release];

}
/////////////////////////////////

#import "SecondViewControlle.h"

@interface
SecondViewControlle ()

@end

@implementation SecondViewControlle

- (void)viewDidLoad {

[super
viewDidLoad];

// Do any additional setup after loading the view.

// self.view.backgroundColor =[UIColor grayColor];

self.view.backgroundColor
=[[UIColor
alloc]
initWithPatternImage:[UIImage
imageNamed:@"/Users/dllo/Desktop/UI/UI03_UIViewController/UI03_UIViewController/asdasd.jpg"]];

///标题是返回,边框,弧度,点击方法

UIButton *button =[UIButton
buttonWithType:UIButtonTypeSystem];

button.frame=CGRectMake(100,
100, 150,
50);

button.backgroundColor =[UIColor
orangeColor];

[self.view
addSubview:button];

[button setTitle:@"返回"
forState:UIControlStateNormal];

button.layer.borderWidth =1;

button.layer.cornerRadius =25;

[button addTarget:self
action:@selector(cile:)
forControlEvents:UIControlEventTouchUpInside];

}

-(void)cile:(UIButton *)button

{

///返回

[self
dismissViewControllerAnimated:YES
completion:^{

}];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: