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)的更多相关文章

  1. ios成长之每日一遍(day 8)

    这几天都有一些任务要跟, 把ios的学习拉后, 看看要抓紧咯, 看看轮到的学习的是UITableView. BIDAppDelegate.h #import <UIKit/UIKit.h> ...

  2. ios成长之每日一遍(day 5)

    iOS 屏幕方向那点事儿http://zhenby.com/blog/2013/08/20/talk-ios-orientation/ 针对当前的屏幕方向进行对应的代码布局 BIDViewContro ...

  3. ios成长之每日一遍(day 3)

    今天要介绍一下更多的控键使用, 当然也会对上一篇说的控件做一个巩固, 所以这一篇涉及到的控键会包括 UIImage.UITextField.UIButton.UILabel.UISwitch.以及 U ...

  4. ios成长之每日一遍(day 1)

    Hello world开始. 这里不讨论如何创建项目导入项目.由于趁上班时间打酱油所以也不谈细节, 只谈具体项目的实现与关键流程的解析, 只供本人实际程况使用.不喜请移驾. 首先来谈谈 AppDele ...

  5. ios成长之每日一遍(day 7)

    今天到UITabBarController 结合 UIPickView, 这里一共有5个实现, 由浅到易. 其实在IB上面使用UITabBarController很简单, 就像平常拖控件一样拖到界面上 ...

  6. ios成长之每日一遍(day 4)

    今天, 主要讲四种常见的问题, 废话不多说了, 直接开始. 自动布局:这个我发现有一篇文章写得非常好, 直接表明出地http://www.cocoachina.com/applenews/devnew ...

  7. ios成长之每日一遍(day 2)

    接着下来简单说说Label(相当于android的textview)和button的使用, 由于都是与上篇的AppDelegate一致, 所以这一篇就说说ViewController与xib的使用呗. ...

  8. iOS:从头捋一遍VC的生命周期

    一.介绍 UIViewController是iOS开发中的核心控件,没有它那基本上任何功能都无法实现,虽然系统已经做了所有控件的生命维护,但是,了解它的生命周期是如何管理还是非常有必要的.网上有很多教 ...

  9. IOS成长之路-用NSXMLParser实现XML解析

    再次对xml进行解析,又有了些理解,如果有不对的地方,请给小弟指出,谢谢! <?xml version="1.0" encoding="UTF-8"?&g ...

随机推荐

  1. Oracle JDK vs OpenJDK

    OpenJDK是Sun在2006年末把Java开源而形成的项目,这里的“开源”是通常意义上的源码开放形式,即源码是可被复用的,例如IcedTea.UltraViolet都是从OpenJDK源码衍生出的 ...

  2. koa+orm2

    koa+orm2 koa是由 Express 原班人马打造的新的web框架.套用其官方的说法:Koa 应用是一个包含一系列中间件 generator 函数的对象. 这些中间件函数基于 request ...

  3. ref:Spring JdbcTemplate+JdbcDaoSupport实例

    ref:https://www.yiibai.com/spring/spring-jdbctemplate-jdbcdaosupport-examples.html 在Spring JDBC开发中,可 ...

  4. InvokeRepeating重复定时器

    JS // Starting in 2 seconds.// a projectile will be launched every 0.3 secondsvar projectile : Rigid ...

  5. 错误跳转js

    <script type="text/javascript"> var t = 5; //倒计时的秒数 function showTime(){ document.ge ...

  6. [POI2013]Morskie opowieści

    [POI2013]Morskie opowieści 题目大意: 一个\(n(n\le5000)\)点\(m(m\le5000)\)边无向图,边权均为\(1\),有\(k(k\le10^6)\)个询问 ...

  7. 20172302『Java程序设计』课程 结对编程练习_四则运算第二周阶段总结

    一.结对对象 姓名:周亚杰 学号:20172302 担任角色:驾驶员(周亚杰) 伙伴第二周博客地址 二.本周内容 (一)继续编写上周未完成代码 1.本周继续编写代码,使代码支持分数类计算 2.相关过程 ...

  8. java并发基础(四)--- 取消与中断

    <java并发编程实战>的第7章是任务的取消与关闭.我觉得这一章和第6章任务执行同样重要,一个在行为良好的软件和勉强运行的软件之间的最主要的区别就是,行为良好的软件能很完善的处理失败.关闭 ...

  9. spring data jpa在使用PostgreSQL表名大小写的问题解决

    国内的文章看了一遍,其实没找到根本问题解决方法,下面将列举这一系列的问题解决方法: 1.在配置文件增加如下配置: spring.jpa.hibernate.naming.physical-strate ...

  10. webdings 和 wingdings 字体

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...