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 ...
随机推荐
- js如何判断访问来源是来自搜索引擎(蜘蛛人)还是直接访问
以下javascript脚本代码可以实现判断访问是否来自搜索引擎.代码如下: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 <scri ...
- .net MVC 登陆模块后台代码
首先是拦截器 public class AuthLoginAttribute : ActionFilterAttribute { public bool IsLogin = true; /// < ...
- 【Java】 大话数据结构(10) 查找算法(1)(顺序、二分、插值、斐波那契查找)
本文根据<大话数据结构>一书,实现了Java版的顺序查找.折半查找.插值查找.斐波那契查找. 注:为与书一致,记录均从下标为1开始. 顺序表查找 顺序查找 顺序查找(Sequential ...
- Github如何撤销提交并清除痕迹
1.在命令行工具中进入项目目录 cd /Users/mac.manon/workspace/QuickCodes 2.sudo git reset --hard HEAD~4 根据提示输入本系统登录密 ...
- linux学习笔记-3.文件相关命令
1.进入到用户根目录 cd ~ 或者 cdcd ~hadoop回到原来路径cd - 2.查看文件详情 stat a.txt 3.移动 mv a.txt /ect/改名mv b.txt a.txt移动并 ...
- Java8 Lambda 之 Collection Stream
Lambda 之 Collection Stream Collection.stream() 测试实体类 class Demo { private Long id; private String na ...
- C#泛型的抗变与协变
C#泛型的抗变与协变 学习自 C#本质论6.0 https://www.cnblogs.com/pugang/archive/2011/11/09/2242380.html Overview 一直以来 ...
- greenDao 介绍
greenDAO是一个针对Android的轻快速ORM解决方案,它将对象映射到SQLite数据库.http://greenrobot.org/greendao/ greenDAO is a light ...
- ZOJ.3551.Bloodsucker(期望DP)
题目链接 \(Description\) 有1个吸血鬼和n-1个人,每天有且只会有两个人/吸血鬼相遇,如果是人与吸血鬼相遇,那个人会有p的概率变成吸血鬼:否则什么也不发生.求n个都变成吸血鬼的期望天数 ...
- python3 开发面试题(collections中的Counter)6.7
''' 编写Python脚本,分析xx.log文件,按域名统计访问次数 xx.log文件内容如下: https://www.sogo.com/ale.html https://www.qq.com/3 ...