本章类容:介绍如何新建一个页面,打开另一个页面

1.在前面中,在工程Appdelegate.m 里面程序第一个走的方法,新建一个窗口,视图,控制器,可视化等,

2.然后在ViewController.m里面viewDidLoad()方法里面 随便写上点信息,方便分辨第一页和第二页,添加个按钮通过点击调转到第二页面

代码:

// 窗口背景色

self.view.backgroundColor = [UIColor whiteColor];

#pragma make UILable //《编译器里面的标记,便于查找》

  UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 414, 50)];

// 文字

[lab setText:@"ViewController"];

//文字颜色

lab.backgroundColor = [UIColor whiteColor];

// label 的背景色

lab.backgroundColor = [UIColor darkGrayColor];

//文字居中

lab.textAlignment = NSTextAlignmentCenter;

//文字大小

[self.view addSubview:lab];

#pragma make UIButton

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];

//按钮文字

[btn setTitle:@"下一页" forState:UIControlStateNormal];

//按钮颜色

[btn setTintColor:[UIColor blueColor]];

//按钮位置

btn.frame = CGRectMake(150, 500, 80, 35);

//背景颜色

btn.backgroundColor = [UIColor blueColor];

[btn addTarget:self action:@selector(BtnClick:) forControlEvents:UIControlEventTouchUpInside];//《按钮事件》

//添加到窗口

[self.view addSubview:btn];

//添加面ban

UIView *yellowView = [[UIView alloc]init];

//用Bounds

yellowView.bounds = CGRectMake(0, 0, 150, 150);

//用函数获取 宽高

// yellowView.bounds = CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetMidX(self.view.frame));

//通过算法定位到中间   前面两个点为set get 方放的点 后面为c语言的结构

//yellowView.center = CGPointMake(self.view.frame.origin.x/2, self.view.frame.origin.y/2);

yellowView.center = self.view.center;

yellowView.backgroundColor = [UIColor yellowColor];

[self.view addSubview:yellowView];

UIView *blueView = [[UIView alloc] init];

blueView.bounds = CGRectMake(0, 0, CGRectGetWidth(yellowView.frame), CGRectGetHeight(yellowView.frame));

//蓝色面板的位置

blueView.center = CGPointMake(self.view.center.x - 75 , self.view.center.y - 75 );

blueView.backgroundColor = [UIColor blueColor];

[self.view addSubview:blueView];

//改变视图同意页面的层次

[self.view sendSubviewToBack:yellowView];

4.command + n 新建一个类,并且在ViewController.m 到如新建类

5.按钮事件:

-(void)BtnClick:(UIButton *)button

{

//创建第二个页面 刚才创建的类初始化一个对象

DetaiViewController *dvc = [[DetaiViewController alloc]init];

//调用此方法推送到第二个页面  由当前控制去 推送到 第二个 dvc 页面 推送后要做的事为空;

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

  //图片推送的方式

dvc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;    //翻转样式

//dvc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;    //图片缩回

//dvc.modalTransitionStyle = UIModalTransitionStylePartialCurl;    //闪切图片

//dvc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;    //渐变

}

5.打开二个页面随便设置个背景颜色等,就可以看到效果了。

6.如何返回到第一页,来到新创建的第二个类里面,在程序第一次走的viewDidLoad 方法里面 添加个UIButton 按钮 并且添加上点击事件

#pragma make UIButton

UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];

btn.frame = CGRectMake(150, 500, 80, 35);

[btn setTitle:@"上一页" forState:UIControlStateNormal];

[btn setTintColor:[UIColor yellowColor]];

btn.backgroundColor = [UIColor blueColor];

[btn addTarget:self action:@selector(BtnClick:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:btn];

//点击事件BtnClick()的方法 ,销毁当前页面,

-(void)BtnClick:(UIButton *)button{

//通过模态推送出来,销毁掉创建的页面

[self dismissViewControllerAnimated:YES completion:nil]; // completion:结束后做什么

}

// 完整的页面切换就完成了。

ios 初体验<页面切换>的更多相关文章

  1. ios 初体验<UIButton 控件>

    1.创建UIButton 跟其他方式不同,不是直接alloc,init 创建 用工厂化方式创建 UIButton *sureBtn = [UIButton buttonWithType:UIButto ...

  2. ios 初体验<UILabel控件>

    创建控件: UILabel *label = [[UILabel alloc]init]; //设置控件大小 label.frame = CGRectMake(50,100,300,40);//分别为 ...

  3. Unity3d IOS中的IGUI控件

    Unity3d IOS中的IGUI控件 @灰太龙  群63438968 我讲一下IOS中用的UI,我们采用IGUI,需要使用IGUI的高版本,在Unity3d 4.2中也可以使用的! 之前IGUI有个 ...

  4. Xamarin iOS教程之页面控件

    Xamarin iOS教程之页面控件 Xamarin iOS 页面控件 在iPhone手机的主界面中,经常会看到一排小白点,那就是页面控件,如图2.44所示.它是由小白点和滚动视图组成,可以用来控制翻 ...

  5. iOS学习之UIPickerView控件的关联选择

    接上篇iOS学习之UIPickerView控件的简单使用 接着上篇的代码 http://download.csdn.net/detail/totogo2010/4391870 ,我们要实现的效果如下: ...

  6. IOS版App的控件元素定位

    前言 Android版App的控件元素可以通过Android studio自带的工具uiautomatorviewer来协助定位! IOS版App的控件元素可以通过Appium来实现(未实现),或ap ...

  7. iOS中UIButton控件的用法及部分参数解释

    在UI控件中UIButton是极其常用的一类控件,它的类对象创建与大多数UI控件使用实例方法init创建不同,通常使用类方法创建: + (id)buttonWithType:(UIButtonType ...

  8. IOS开发中设置控件内容对齐方式时容易混淆的几个属性

    IOS开发中四个容易混淆的属性: 1. textAligment : 文字的水平方向的对齐方式 1> 取值 NSTextAlignmentLeft      = 0,    // 左对齐 NST ...

  9. iOS学习之基础控件

    一.UILabel      1.UILabel(标签):是显示文本的空间.在App中UILabel是出现频率最高的控件.      2.UILabel是UIView的子类,作为子类一般是为了扩充父类 ...

  10. iOS面试题03-UI控件

    UI控件面试题 1.怎么解决缓存池端的问题(cell) 回答:1.>OS中不存在缓存池的情况,因为通常我们iOS开发,对象都是在需要的时候才会创建, 有种常用的说话叫做懒加载,还有在UITabl ...

随机推荐

  1. PocScan的搭建与使用

    安装Docker, 然后下载镜像 $ sudo curl -sSL https://get.daocloud.io/docker | sh $ sudo systemctl start docker ...

  2. JavaScript数组遍历(迭代)方法 8种

    最近工作中经常涉及到数据的处理,数组尤其常见,经常需要对其进行遍历.转换操作,网上的文章零零散散,不得已自己又找出红宝书来翻出来看,顺便记一笔,便于以后查询. 数组常用的方法 ECMAScript5为 ...

  3. python8 字符串操作

    name = "my name is {name} and i am {year} old" print(name.capitalize()) print(name.count(& ...

  4. React Native 系列(七) -- ListView

    前言 本系列是基于React Native版本号0.44.3写的.几乎所有的App都使用了ListView这种组件,这篇文章将学习RN中ListView的平铺样式和分组样式. ListView平铺样式 ...

  5. PAT1074 Reversing Linked List (25)详细题解

    02-1. Reversing Linked List (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue ...

  6. sshpass做秘钥分发,ansible做自动化运维工具

    最近公司机器的增多,顺便还要上报表系统,考虑到服务器越来越多,手工的管理显得越来的越吃力,所以打算推进公司自动化运维工具的使用. 推进的过程中,一步一个坑踩过来的.由于公司之前未运用过自动化运维工具, ...

  7. python学习===从键盘输入一些字符,逐个把它们写到磁盘文件上,直到输入一个 # 为止。

    #!/usr/bin/python # -*- coding: UTF-8 -*- if __name__ == '__main__': from sys import stdout filename ...

  8. go环境的安装~

    Golang环境搭建 Golang github地址:https://github.com/golang/go Golang的环境下载:https://golang.org/dl/ 安装过程就是nex ...

  9. Centos定时任务

    安装crontab:yum install crontabs说明:/sbin/service crond start //启动服务/sbin/service crond stop //关闭服务/sbi ...

  10. mysql为什么范围查询(>,<,between,%like,like%)之后的索引无效

    因为使用了范围索引,所以会使用满足范围的所有的值,也就是说存储引擎在这个时候会提取出满足之后条件的所有值,并遍历获取满足之后条件的值. http://www.itpub.net/thread-1901 ...