ios成长之每日一遍(day 6)
toolBar上的View Switcher
BIDAppDelegate.h
- #import <UIKit/UIKit.h>
- @class BIDSwitchViewController;
- @interface BIDAppDelegate : UIResponder <UIApplicationDelegate>
- @property (strong, nonatomic) UIWindow *window;
- @property (strong, nonatomic) BIDSwitchViewController *switchViewController;
- @end
BIDAppDelegate.m
- #import "BIDAppDelegate.h"
- #import "BIDSwitchViewController.h"
- @implementation BIDAppDelegate
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- {
- self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
- // Override point for customization after application launch.
- self.switchViewController = [[BIDSwitchViewController alloc]
- initWithNibName:@"SwitchView" bundle:nil];
- UIView *switchView = self.switchViewController.view; // 获取controller所管理的view
- CGRect switchViewFrame = switchView.frame; // 获取view的x,y,width,height
- switchViewFrame.origin.y += [UIApplication
- sharedApplication].statusBarFrame.size.height; // 设定高度是在statusbar下
- switchView.frame = switchViewFrame;
- [self.window addSubview:switchView]; // 把view添加到window
- self.window.backgroundColor = [UIColor whiteColor];
- [self.window makeKeyAndVisible];
- 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 should 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 many 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 previously 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
BIDSwitchViewController.h
- #import <UIKit/UIKit.h>
- @class BIDYellowViewController;
- @class BIDBlueViewController;
- @interface BIDSwitchViewController : UIViewController
- @property (strong, nonatomic) BIDYellowViewController *yellowViewController;
- @property (strong, nonatomic) BIDBlueViewController *blueViewController;
- - (IBAction)switchViews:(id)sender;
- @end
BIDSwitchViewController.m
- #import "BIDSwitchViewController.h"
- #import "BIDYellowViewController.h"
- #import "BIDBlueViewController.h"
- @interface BIDSwitchViewController ()
- @end
- @implementation BIDSwitchViewController
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.blueViewController = [[BIDBlueViewController alloc]
- initWithNibName:@"BlueView" bundle:nil]; // 根据xib创建ViewController
- [self.view insertSubview:self.blueViewController.view atIndex:]; // 把blueViewController的view插进索引为0的根view中
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- if (self.blueViewController.view.superview == nil) { // 如果blueViewController的view的根view是nil
- self.blueViewController = nil; // 把blueViewController置空
- } else {
- self.yellowViewController = nil; // 否则yellowViewController置空
- }
- }
- - (IBAction)switchViews:(id)sender {
- [UIView beginAnimations:@"View Flip" context:nil]; // UIView开始动画
- [UIView setAnimationDuration:10.25]; // 设置动画时间
- [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; // 定义动画块加速减速的方式
- if (self.yellowViewController.view.superview == nil) {
- if (self.yellowViewController == nil) { // yellowViewController为空
- self.yellowViewController =
- [[BIDYellowViewController alloc] initWithNibName:@"YellowView"
- bundle:nil];
- }
- [UIView setAnimationTransition:
- UIViewAnimationTransitionFlipFromRight
- forView:self.view cache:YES]; // 设置动画方式,并指出动画发生的位置
- [self.blueViewController.view removeFromSuperview]; // 把blueViewController的view从他的父view中移除
- [self.view insertSubview:self.yellowViewController.view atIndex:]; // 把yellowViewController的view插进索引为0的根view中
- } else {
- if (self.blueViewController == nil) {
- self.blueViewController =
- [[BIDBlueViewController alloc] initWithNibName:@"BlueView"
- bundle:nil];
- }
- [UIView setAnimationTransition: // bold
- UIViewAnimationTransitionFlipFromLeft // bold
- forView:self.view cache:YES]; // bold
- [self.yellowViewController.view removeFromSuperview];
- [self.view insertSubview:self.blueViewController.view atIndex:];
- }
- [UIView commitAnimations]; // 提交UIView动画
- }
- @end
ios成长之每日一遍(day 6)的更多相关文章
- ios成长之每日一遍(day 8)
这几天都有一些任务要跟, 把ios的学习拉后, 看看要抓紧咯, 看看轮到的学习的是UITableView. BIDAppDelegate.h #import <UIKit/UIKit.h> ...
- ios成长之每日一遍(day 5)
iOS 屏幕方向那点事儿http://zhenby.com/blog/2013/08/20/talk-ios-orientation/ 针对当前的屏幕方向进行对应的代码布局 BIDViewContro ...
- ios成长之每日一遍(day 3)
今天要介绍一下更多的控键使用, 当然也会对上一篇说的控件做一个巩固, 所以这一篇涉及到的控键会包括 UIImage.UITextField.UIButton.UILabel.UISwitch.以及 U ...
- ios成长之每日一遍(day 1)
Hello world开始. 这里不讨论如何创建项目导入项目.由于趁上班时间打酱油所以也不谈细节, 只谈具体项目的实现与关键流程的解析, 只供本人实际程况使用.不喜请移驾. 首先来谈谈 AppDele ...
- ios成长之每日一遍(day 7)
今天到UITabBarController 结合 UIPickView, 这里一共有5个实现, 由浅到易. 其实在IB上面使用UITabBarController很简单, 就像平常拖控件一样拖到界面上 ...
- ios成长之每日一遍(day 4)
今天, 主要讲四种常见的问题, 废话不多说了, 直接开始. 自动布局:这个我发现有一篇文章写得非常好, 直接表明出地http://www.cocoachina.com/applenews/devnew ...
- ios成长之每日一遍(day 2)
接着下来简单说说Label(相当于android的textview)和button的使用, 由于都是与上篇的AppDelegate一致, 所以这一篇就说说ViewController与xib的使用呗. ...
- iOS:从头捋一遍VC的生命周期
一.介绍 UIViewController是iOS开发中的核心控件,没有它那基本上任何功能都无法实现,虽然系统已经做了所有控件的生命维护,但是,了解它的生命周期是如何管理还是非常有必要的.网上有很多教 ...
- IOS成长之路-用NSXMLParser实现XML解析
再次对xml进行解析,又有了些理解,如果有不对的地方,请给小弟指出,谢谢! <?xml version="1.0" encoding="UTF-8"?&g ...
随机推荐
- SqlServer 递归查询树
递归关于进行树形结构的查询: 一:简单的树形结构代码. -- with一个临时表(括号中是你要查询的列名) with temp(ID,PID,Name,curLevel) as ( --1:初始查询( ...
- CI框架+Umeditor上传图片配置信息
Umeditor提供了一个上传文件通用的类Uploader.class.php, 首先将Uploader.class.php类放入CI框架的libraries目录下更名为Myuploader.php然 ...
- .NetCore使用FluentValidation实现友好验证提示
Nuget包导入FluentValidation.AspNetCore 官方的用法是在services中添加如下来操作 services.AddMvc().AddFluentValidation(co ...
- priority_queue<int>q;
priority_queue<int>q;//默认不递增q.size();//q中有几个元素q.pop();//删除队首q.top();//返回队首元素q.push();//在队列中插入一 ...
- 浅谈2-SAT(待续)
2-SAT问题,其实是一个逻辑互斥问题.做了两道裸题之后仔细想来,和小时候做过的“有两个女生,如果A是女生,那么B一定不是女生.A和C性别相同,求A.B.C三人的性别.”几乎是一样的. 对于这道题我们 ...
- 【Ray Tracing in One Weekend 超详解】 光线追踪1-2
今天我们开始进入正篇 Chapter 3: Rays, a simple camera, and background 对于所有的光线追踪器,基本都有一个光线类,计算沿光线看到的颜色. 我们的光线是一 ...
- python全栈开发之匿名函数和递归函数
python 匿名函数和递归函数 python全栈开发,匿名函数,递归函数 匿名函数 lambda函数也叫匿名函数,即函数没有具体的名称.是为了解决一些功能很简单需求而设计的一句话函数.如下: #这段 ...
- HttpServlet Service方法
service() 方法是执行实际任务的主要方法.Servlet 容器(即 Web 服务器)调用 service() 方法来处理来自客户端(浏览器)的请求,并把格式化的响应写回给客户端. 每次服务器接 ...
- SDOI2013 R1 Day2
目录 2018.3.25 Test 总结 T1 BZOJ.3129.[SDOI2013]方程(扩展Lucas 容斥) T2 洛谷.3305.[SDOI2013]费用流(最大流ISAP 二分) T3 B ...
- pygame系列_小球完全弹性碰撞游戏_源码下载
之前做了一个基于python的tkinter的小球完全碰撞游戏: python开发_tkinter_小球完全弹性碰撞游戏_源码下载 今天利用业余时间,写了一个功能要强大一些的小球完全碰撞游戏: 游戏名 ...