UI03-viewController 视图跳转:

/*  ******今日任务:登陆界面 进行最后的优化 ,封装控件 (2)viewController (3)MVC 思想(4)对于屏幕旋转,内存异常的处理,(5)容器视图控制器,四个方法的使用 视图切换的方式

1.登陆界面的优化,

(1)封装的设计模式的,组合类模式的装饰者模式,复合设计模式,23种设计模式    一个自定义控件里面有多个系统控件,

(1)自定义一个视图,基于UI view,把包含的系统控件作为。h里的属性,

(2)在.m中重写初始化方法,把各个系统控件的属性写死,注意各个控件的尺寸分布,如下,

尽量运用系统属性确定边界

-(instancetype)initWithFrame:(CGRect)frame{

self=[super initWithFrame:frame];

if (self) {

//初始化2个属性

_lable=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 70, 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 视图控制器,

(1)出现的原因:

1)分担appdelegate的工作。实现模块独立,一个视图控制器 相当于一个界面

2)高內聚,低耦合。

3)模块化编程,方便配合开发。

(2)分担的工作,

1)控制视图的大小变化,布局,响应事件,

2)检测并处理内存警告

3)检测并处理屏幕的旋转

4)进行视图的切换

3.如何创建视图控制器,

(1) 创建文档commad + n  firstViewController : UIViewController

(2) 在appdelegate里面 指定在window根视图控制器 为自己创建的视图控制器

[在7的时候要求必须指定根视图控制器,不指定会崩溃退出]

firstViewController *fvc=[[firstViewController alloc]init];

self.window.rootViewController=fvc;

(3)controller 是默认自带一个view 的,大小是和屏幕一样大的,

4. mvc

(1)在代理文件里,把window的rootViewController给自定义的contrller(基于UIviewcontrller)。 新建contrller- 引入头文件-初始化-赋值  四步。

(2)自定义视图(基于UIview),替换contrller的默认视图:  引入头文件   自定义视图作为contrller的属性   重写loadView (加载父视图,初始化自定义视图,赋值  )

(3)  在自定义的视图上 创建控件和方法   : .h创建控件属性,.m 重写初始化方法:加载父视图,在自己创建的方法中 定义控件的属性(self setbutton),给控件的各属性赋值。

(4)button 的响应事件在controller 里的DidLoad中实添加,在下方实现响应方法的实现(跳转).

5.屏幕旋转

(1).屏幕旋转,不只要在配置文件里勾选,代码也要设置,

支持左和右旋转的时候,    -(NSUInteger)supportedInterfaceOrientations     {      return UIInterfaceOrientationMaskAll ;   }

(2)屏幕即将进入旋转的时候调用,旋转之后的size的大小,把界面的用户响应关掉,

-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator{

self.view.userInteractionEnabled=YES;

}

(2)这个方法是支持旋转的方向,不是手机的旋转,而是屏幕的旋转,因为屏幕的内容与手机旋转方向是相反的。

-(NSUInteger)supportedInterfaceOrientations

{      return UIInterfaceOrientationMaskAll ;   }

这个return回去的是屏幕内容旋转的方向。

(3)

-(void)layoutSubviews{

//可以根据这个方法获取当前手机的方向

if  ([UIApplication sharedApplication].statusBarOrientation==UIInterfaceOrientationLandscapeLeft )

NSLog(@"做作");

}

6.内存异常警告  系统将要崩溃时

内存警告,当内存崩溃的时候会调用这个方法。

当内存快要崩溃的时候没,进行数据保存的工作,把数据储存成文档,或者放到数据库中,防止数据丢失。

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

8.视图跳转:

(1)  响应加载 视图  -(void)dengLu:(UIButton*)buu{

ZhuceViewController *zhuce=[[ZhuceViewController alloc]init];

[self presentViewController:zhuce animated:YES completion:nil];

}

(2)

取消响应者,回到初始界面.

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

[self dismissViewControllerAnimated:YES completion:nil];

}

点任意地方回收键盘。

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

[self.view endEditing:YES];

}

时间: 2024-08-09 22:01:48

UI03-viewController 视图跳转:的相关文章

Unity3D与iOS的交互设计&lt;ViewController 的跳转&gt;

原地址:http://www.aichengxu.com/article/%CF%B5%CD%B3%D3%C5%BB%AF/28797_12.html Unity3D与iOS的交互设计<ViewController 的跳转>,有需要的朋友可以参考下. 这也是第一次做这样的需求,也是公司的需要呀.做出这个真是一言难尽呀... 小弟主要不是搞iOS开发的,一直以来都是开发Android开发,只是昨天被老大叫过去做一下iOS的二维码扫描.有点iOS基础的我,只好到处搜索了.然后,二维码扫描做好了,遇

Swfit中视图跳转

1.跳转到任一UIViewController var sb = UIStoryboard(name: "Main", bundle:nil) var vc = sb.instantiateViewControllerWithIdentifier("ChooseViewController") as ChooseViewController self.presentViewController(vc, animated:true, completion:nil) 2

dismissViewController实现多个模态视图跳转

最近实现的一个需求需要用到模态视图,所以少不了与dismissViewController方法打交道.本文主要讲一讲在使用dismissViewController方法过程中遇到的那些坑. 由于业务逻辑比较特殊,程序中需要在A试图控制器中present B试图控制器的视图,B视图控制器需要present C视图控制器中的视图.最后从C直接返回A. dismissViewControllerAnimated方法并不难用,其原型为: - (void)dismissViewControllerAnim

[100天Swift]第五天:用代码实现视图跳转

前言: 在Xcode推出StoryBoard的时候,Xcode可以更简单的,更聪明的帮助我们做一些简单的事情,快速建立一个Base的App,可是作为一个习惯了写代码的“码农”,还是需要知道如何通过代码去实现这些“简单”的事情. Swift中的视图跳转 1.跳转到任一UIViewController var sb = UIStoryboard(name: "Main", bundle:nil) var vc = sb.instantiateViewControllerWithIdenti

设置背景为白色,避免从A视图跳转到B视图的时候出现卡顿

- (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; } 设置背景为白色,避免从A视图跳转到B视图的时候出现卡顿

IOS 视图跳转的总结

1.[self.view addSubView:view];和[self.window addSubView:view];需要注意,此方法只是把页面(view)加在当前页面(view)上,控制器(viewController)还是原来那个控制器.此时再用[self.navigationColler pushViewController:animated:];和 [self.navigationController popViewControllerAnimated:]; 是不行的.要想使用pus

iOS中的视图跳转的三种方式(代码跳转,根据桥跳转,按钮跳转)

#import "ViewController.h" #import "SecondViewController.h" @interface ViewController () @property (retain, nonatomic) IBOutlet UITextField *textField; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // D

pushViewController, popViewController, presentViewController, dismissViewController---关于视图跳转的总结

1.[self.view addSubView:view];和[self.window addSubView:view];需要注意,此方法只是把页面(view)加在当前页面(view)上,控制器(viewController)还是原来那个控制器.此时再用[self.navigationColler pushViewController:animated:];和 [self.navigationController popViewControllerAnimated:]; 是不行的.要想使用pus

IOS中在自定义控件(非视图控制器)的视图跳转中 代理方法与代码块的比较

//代码块与代替代理的设计方法 我就以在自定义视图中(非视图控制器,不能实现视图控制功能),通过代理和代码块两种方法分别实现视图的跳转,进行对比 首先自定义了一个视图,上面有一个已经注册了得BUtton点击监控事件方法-(void)event{};视图的跳转就在这个方法中实现(注意:这个button不在视图控制器里面,就算导了相关头文件,也不能跳转,所以只能通过代理方法,或者代码块等,在这个button(在自定义控件空,非视图控制器)方法中调用相关方法,在视图控制器中去实现) 代理实现方法: 在