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. 【LOJ】#2546. 「JSOI2018」潜入行动

    题解 dp[i][j][0/1][0/1]表示以\(i\)为根的子树,用了\(j\)个,i点选了或者没选,i点被覆盖或没被覆盖 转移比较显然,但是复杂度感觉不太对? 其实转移到100个的时候就使第二维 ...

  2. 高能天气——团队Scrum冲刺阶段-Day 7 总结

    高能天气--团队Scrum冲刺阶段-Day 7 总结 今日完成任务 于欣月:修改项目说明书,帮助修改应用 余坤澎:进行应用整合的收尾工作 康皓越:进行应用整合的收尾工作 范雯琪:修改项目说明书,完成项 ...

  3. 命令行fuck神器

     文章 thefuck  git thefuck

  4. SmartSVN11 Mac版 注册码序列号

    Name=apipostAddress=1337 iNViSiBLE Str.Email=3257132998@qq.comFreeUpdatesUntil=2099-09-26LicenseCoun ...

  5. Java 内部类.md

    Java 内部类 学习自 <Java编程思想> Overview 什么是内部类? Thinking In Java 中如此定义: 将一个类的定义放在里另一个类的定义的内部,这就是内部类. ...

  6. Android对Sqlite数据库的增删改查

    SqLite 数据库 Google 为我们提供了sqlite相关的api SqLiteOpenHelper 这是一个抽象的类 如果想要使用的话,需要其他的类去继承他 SqLiteDatabase 类 ...

  7. 快速排序之Java实现

    快速排序之Java实现 代码: package cn.com.zfc.lesson21.sort; /** * * @title QuickSort * @describe 快速排序 * @autho ...

  8. 有强大的cURL,忘掉httpclient的吧!

    这段时间想做一个网页采集的程序,由于一网站采用了防采集的办法,我的httpclient总是在登录后无法获取到我想要过去的链接.在无数次的跟踪过后发现原来人家给返回的是javascript拼成的页面,而 ...

  9. Serilog中的Jobject/Jtoken对象序列化的问题

    今天使用Serilog打印object对象的时候,发现Jtoken对象输出成 [[[]] 这种形式了,本来以为是传入参数的问题,确认了几遍后发现确实是Serilog输出的问题.github上也有人提出 ...

  10. LPC18xx/43xx SWD/JTAG Debug Connector