appdelegete.m
#import "AppDelegate.h"
#import "FirstViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
_window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
[_window setBackgroundColor:[UIColor whiteColor]];
//1.创建第一个视图控制器的对象
FirstViewController *first = [[FirstViewController alloc]init];
//2.作为window的根视图控制器
_window.rootViewController = first;
[_window makeKeyAndVisible];
return YES;
}
@end
FirstViewController.m
//
// FirstViewController.m
// 05-模态视图控制器的切换
//
// Created by 千锋 on 16/4/12.
// Copyright (c) 2016年 樊娟. All rights reserved.
//
#import "FirstViewController.h"
#import "SecondViewController.h"
#import "UIView+FJView.h"
@interface FirstViewController ()
@end
@implementation FirstViewController
#pragma mark -点击按钮实现跳转
- (void)nextView:(UIButton *)btn{
// //1.创建下一个界面的对象
SecondViewController *second = [[SecondViewController alloc]init];
//
//#pragma mark -模态化弹出一个界面
// //2.模态化弹出一个界面
// //参数1:需要弹出的那个视图控制器对象
// //参数2:是否有动画
// //参数3:弹出动画结束后需要做的事情.写在这个block里
//// [self presentViewController:second
//// animated:NO completion:^{
////
//// NSLog(@"下一个界面弹出后需要做的事情写在这儿");
////
//// }];
////
//
//#pragma mark -字符串转场动画
// //3.切换动画(转场动画) -- 专门用于界面之间切换的动画效果
// //a.创建一个转场动画的对象
//
// CATransition * transition = [CATransition animation];
//
// //b.设置动画时间(单位是秒)
// transition.duration = 1;
//
// //c.设置动画效果
//
// //字符串
//// pageCurl 向上翻一页
//// pageUnCurl 向下翻一页
//// rippleEffect 滴水效果
//// suckEffect 收缩效果,如一块布被抽走
//// cube 立方体效果
//// oglFlip 上下翻转效果
//// cameraIrisHollowOpen 打开相机的效果
//// cameraIrisHollowClose 关闭相机的效果
//
//#pragma mark -宏定义动画效果
//// kCATransitionFade 交叉淡化过渡
//// kCATransitionMoveIn 新视图移到旧视图上面
//// kCATransitionPush 新视图把旧视图推出去
//// kCATransitionReveal 将旧视图移开,显示下面的新视图
//
// [transition setType:@"pageCurl"];
//
//
// //d.设置动画方向(不是所有的动画效果都有效)
//#pragma mark -设置动画方向
//// kCATransitionFromRight;
//// kCATransitionFromLeft(默认值)
//// kCATransitionFromTop;
//// kCATransitionFromBottom
// [transition setSubtype:@"fromLeft"];
//
//
// //e.添加动画效果
// //转场动画只能添加到layer
// [self.view.window.layer addAnimation:transition forKey:nil ];
//
// //在这儿后面的所有的视图切换都有上面的动画效果
// //必须关闭切换视图自带的动画效果
// [self presentViewController:second animated:NO completion:nil];
[self.view.window addTransitionAnimationWithDuration:0.1 animationType:(FJTransitionType) FJ_pageCurl direction:FJ_UP];
[self presentViewController:second animated:YES completion:nil];
}
#pragma mark -生命周期相关的方法
//加载view的时候会调用
- (void)loadView{
[super loadView];
NSLog(@"%s",__func__);
}
//view已经加载成功
- (void)viewDidLoad {
[super viewDidLoad];
//设置当前这个界面的背景颜色
self.view.backgroundColor = [UIColor lightGrayColor];
//添加一个按钮
UIButton *button = [[UIButton alloc]initWithFrame:
CGRectMake(100, 100, 50, 50)];
button.backgroundColor = [UIColor orangeColor];
[self.view addSubview:button];
//添加事件
[button addTarget:self action:@selector(nextView:)
forControlEvents:UIControlEventTouchUpInside];
NSLog(@"%s",__func__);
}
//view将要显示
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
NSLog(@"%s",__func__);
}
//view已经显示
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
NSLog(@"%s",__func__);
}
//view将要消失
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
NSLog(@"%s",__func__);
}
//view已经消失
-(void)viewDidDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
NSLog(@"%s",__func__);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
SecondViewController.m
#import "SecondViewController.h"
#import "FirstViewController.h"
#import "UIView+FJView.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
#pragma mark -点击按钮回到第一个页面
- (void)preView:(UIButton *)btn{
//1.回到上一个界面
//让当前这个视图控制器对象消失
//参数1:是否动画
//参数2:动画结束后的事情在这里写block
//self可以调用这个方法的前提是:self对象是通过present方式弹出的
//当前调用dismiss方法的视图控制器对象,调用完dismiss方法后会被销毁;
[self.view.window addTransitionAnimationWithDuration:0.3 animationType:
FJ_rippleEffect direction:FJ_DOWN];
[self dismissViewControllerAnimated:NO completion:^{
}];
}
#pragma mark - 第二个页面的生命周期方法
//加载view的时候会调用
- (void)loadView{
[super loadView];
NSLog(@"%s",__func__);
}
//view已经加载成功
- (void)viewDidLoad {
[super viewDidLoad];
//设置当前这个界面的背景颜色
self.view.backgroundColor = [UIColor orangeColor];
//添加一个按钮
UIButton *button = [[UIButton alloc]initWithFrame:
CGRectMake(100, 100, 50, 50)];
button.backgroundColor = [UIColor blackColor];
[self.view addSubview:button];
//添加事件
[button addTarget:self action:@selector(preView:)
forControlEvents:UIControlEventTouchUpInside];
NSLog(@"%s",__func__);
}
//view将要显示
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
NSLog(@"%s",__func__);
}
//view已经显示
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
NSLog(@"%s",__func__);
}
//view将要消失
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
NSLog(@"%s",__func__);
}
//view已经消失
-(void)viewDidDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
NSLog(@"%s",__func__);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end