UI3_视图切换
//
// ViewController.m
// UI3_视图切换
//
// Created by zhangxueming on 15/7/3.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "ViewController.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"
#import "FourthViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor redColor]; SecondViewController *secondVC = [[SecondViewController alloc] init];
ThirdViewController *thirdVC = [[ThirdViewController alloc] init];
FourthViewController *fouthVC = [[FourthViewController alloc] init]; [self addChildViewController:secondVC];
[self addChildViewController:thirdVC];
[self addChildViewController:fouthVC]; NSLog(@"count = %li", self.childViewControllers.count); UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeSystem];
btn1.frame = CGRectMake(20, 100, self.view.frame.size.width-40, 50);
btn1.backgroundColor = [UIColor whiteColor];
[btn1 setTitle:@"按钮1" forState:UIControlStateNormal];
[btn1 addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
btn1.tag = 100;
[self.view addSubview:btn1]; UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeSystem];
btn2.frame = CGRectMake(20, 200, self.view.frame.size.width-40, 50);
btn2.backgroundColor = [UIColor whiteColor];
[btn2 setTitle:@"按钮2" forState:UIControlStateNormal];
[btn2 addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
btn2.tag = 101;
[self.view addSubview:btn2]; UIButton *btn3 = [UIButton buttonWithType:UIButtonTypeSystem];
btn3.frame = CGRectMake(20, 300, self.view.frame.size.width-40, 50);
btn3.backgroundColor = [UIColor whiteColor];
[btn3 setTitle:@"按钮3" forState:UIControlStateNormal];
[btn3 addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
btn3.tag = 102;
[self.view addSubview:btn3];
} - (void)btnClicked:(UIButton *)btn
{
//self.childViewControllers
if (btn.tag==100) {
[self.view addSubview:((UIViewController *)[self.childViewControllers objectAtIndex:0]).view];
}
else if(btn.tag ==101)
{
[self.view addSubview:((UIViewController *)[self.childViewControllers objectAtIndex:1]).view];
}
else if(btn.tag ==102)
{
[self.view addSubview:((UIViewController *)[self.childViewControllers objectAtIndex:2]).view];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
//
// FourthViewController.m
// UI3_视图切换
//
// Created by zhangxueming on 15/7/3.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "FourthViewController.h" @interface FourthViewController () @end @implementation FourthViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor yellowColor];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame = CGRectMake(20, 100, self.view.frame.size.width-40, 50);
btn.backgroundColor = [UIColor whiteColor];
[btn setTitle:@"按钮" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
} - (void)btnClicked
{
if (self.view.superview) {
//移除子视图
[self.view removeFromSuperview];
}
}
- (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
//
// ThirdViewController.m
// UI3_视图切换
//
// Created by zhangxueming on 15/7/3.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "ThirdViewController.h" @interface ThirdViewController () @end @implementation ThirdViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor greenColor]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame = CGRectMake(20, 100, self.view.frame.size.width-40, 50);
btn.backgroundColor = [UIColor whiteColor];
[btn setTitle:@"按钮" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
} - (void)btnClicked
{
if (self.view.superview) {
//移除子视图
[self.view removeFromSuperview];
}
} - (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
//
// SecondViewController.m
// UI3_视图切换
//
// Created by zhangxueming on 15/7/3.
// Copyright (c) 2015年 zhangxueming. 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 blueColor]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame = CGRectMake(20, 100, self.view.frame.size.width-40, 50);
btn.backgroundColor = [UIColor whiteColor];
[btn setTitle:@"按钮" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn]; } - (void)btnClicked
{
if (self.view.superview) {
//移除子视图
[self.view removeFromSuperview];
}
} - (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
UI3_视图切换的更多相关文章
- iOS开发系列--视图切换
概述 在iOS开发中视图的切换是很频繁的,独立的视图应用在实际开发过程中并不常见,除非你的应用足够简单.在iOS开发中常用的视图切换有三种,今天我们将一一介绍: UITabBarController ...
- pushViewController addSubview presentModalViewController视图切换
1.pushViewController和popViewController来进行视图切换,首先要确保根视图是NavigationController,不然是不可以用的, pushViewContro ...
- IOS 视图切换动画
我在网上找到的这个小方法,被我举一反三使用的屡试不爽.比如用在,当视图需要执行某一方法跳转到新的一个UIView上,从底层渐变浮到最上层.就是一个不错的视觉效果或者当需要类似keyboard的效果从底 ...
- UI2_视图切换ViewController
// // SubViewController.h // UI2_视图切换 // // Created by zhangxueming on 15/7/3. // Copyright (c) 2015 ...
- UI1_ViewController视图切换及Appdelegate
// // ThirdViewController.h // UI1_ViewController视图切换及Appdelegate // // Created by zhangxueming on 1 ...
- UI2_视图切换
// // ViewController.m // UI2_视图切换 // // Created by zhangxueming on 15/7/1. // Copyright (c) 2015年 z ...
- Tabbar视图切换,返回上一视图,添加item
前面有一篇博文iOS学习之Tab Bar的使用和视图切换 这是在AppDelegate里使用Tabbar,这样的程序打开就是TabbarView了,有时候我们需要给程序做一些帮助页面,或者登录页面,之 ...
- MFC视图切换大全总结
单纯视图之间的切换 单文档多视图切换是我在学习MFC中遇到的一个老大难问题,在今天总算是一一破解了.我觉得视图切换分为三个等级,第一是在未切分窗格的情况下切换视图类:第二是在分割窗格的一个窗格内实行视 ...
- Android的Activity切换动画特效库SwitchLayout,视图切换动画库,媲美IOS
由于看了IOS上面很多开发者开发的APP的视图界面切换动画体验非常好,这些都是IOS自带的,但是Android的Activity等视图切换动画并没有提供原生的,所以特此写了一个可以媲美IOS视图切换动 ...
随机推荐
- android一些系统相关的东西
添加快捷方式和删除快捷方式: private void addShortcut() { Intent shortcut = new Intent( "com.android.launcher ...
- [CSS] Introduction to CSS Columns
Learn how to use CSS columns to quickly lay out fluid columns that are responsive, degrade gracefull ...
- 基数树(radix tree)
原文 基数(radix)树 Linux基数树(radix tree)是将指针与long整数键值相关联的机制,它存储有效率,并且可快速查询,用于指针与整数值的映射(如:IDR机制).内存管理等.ID ...
- 用iDSDT制作声显卡DSDT
已有 2299 次阅读2011-10-24 21:00 |个人分类:Mac| DSDT 快速增加积分秘笈! windows下!--------------------------------第一步.下 ...
- QStyle 新风格的实现
摸索了很久,实际实现才发现很简单. 利用qt助手搜style可以发现style的实现和qapplication有关,在Qapplication里面搜到函数: void QApplication:: ...
- ajax重写,js方法重新
重写Jquery的$.ajax方法 (function($){ //备份jquery的ajax方法 var _ajax=$.ajax; //重写jquery的ajax方法 $.ajax=functio ...
- 使用jmeter对ActiveMQ集群性能方案进行评估--转载
原文地址:http://www.51testing.com/html/78/23978-143163.html 1.测试概要1.1 关于这篇文档中涉及的基于JMS的消息系统能为应用程序提供可靠的,高性 ...
- 架构设计:负载均衡层设计方案(6)——Nginx + Keepalived构建高可用的负载层
1.概述 前两遍文章中,我们一直在说后文要介绍Nginx + Keepalived的搭建方式.这篇文章开始,我们就来兑现前文的承诺,后续的两篇文章我们将介绍Nginx + Keepalived和 LV ...
- Java再学习——Executor,ExecutorService,ScheduledExecutorService与Executors
1,Executor.ExecutorService和ScheduledExecutorService,它们都是接口,它们的关系是ScheduledExecutorService继承ExecutorS ...
- WPF 之 实现TextBox输入文字后自动弹出数据(类似百度的输入框)
1.添加一个数据实体类 AutoCompleteEntry,如下: using System; using System.Collections.Generic; using System.Linq; ...