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 ...
随机推荐
- **CI中的order_by在get_where之前
public function show_list_by_order($array_data, $order_field, $order_mode) { $query = $this->db-& ...
- Linux性能优化之内存优化(二)
前言 不知道大家看完前面一章关于CPU优化,是否受到相应的启发呢?如果遇到任何问题,可以留言和一起探讨这方面的问题.接下来我们介绍一些关于内存方面的知识.内存管理软件包括虚拟内存系统.地址转换.交换. ...
- 【noip模拟赛3】编码
描述 Alice和Bob之间要进行秘密通信,他们正在讨论如何对信息进行加密: Alice:“不如采用一种很简单的加密方式:’A’替换成1,’B’替换成2,„„,’Z’替换成26.” Bob:“这种加密 ...
- 005 jquery过滤选择器-----------(内容过滤选择器)
1.介绍 2.程序 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> < ...
- [转]状态压缩dp(状压dp)
状态压缩动态规划(简称状压dp)是另一类非常典型的动态规划,通常使用在NP问题的小规模求解中,虽然是指数级别的复杂度,但速度比搜索快,其思想非常值得借鉴. 为了更好的理解状压dp,首先介绍位运算相关的 ...
- linux环境下source vimrc提示错误unexpected token `"autocmd"'
编辑完vimrc之后,使用source /etc/vimrc之后报错: $ source /etc/vimrc bash: /etc/vimrc: line 15: syntax error near ...
- Eclipse中从svn中检出maven项目
相信很多初学者都遇到过Eclipse中从SVN检出Maven项目之后看到的目录结构并不是Maven目录结构:或者只能先用SVN将Maven项目签入到本地,然后再用Eclipse导入Maven项目,但是 ...
- python3.5 自带的虚拟环境使用
首先我们要选择一个目录作为虚拟环境的目录, 这里选择c:\myenv cd myenv python -m venv . #在当前目录下创建虚拟环境 创建完成之后,myenv下会多出一些文件 进入sc ...
- [BZOJ3585]mex(莫队+分块)
显然可以离线主席树,这里用莫队+分块做.分块的一个重要思想是实现修改与查询时间复杂度的均衡,这里莫队和分块互相弥补. 考虑暴力的分块做法,首先显然大于n的数直接忽略,于是将值域分成sqrt(n)份,每 ...
- BZOJ.5068.友好的生物(思路)
题目链接 \(Description\) 求\[\max\{\sum_{i=1}^{k-1}(C_i*|a_{x,i}-a_{y,i}|)-C_k*|a_{x,k}-a_{y,k}|\}\] \(So ...