一,工程圖。 二,代碼。 RootViewController.h RootViewController.m ...
一,工程圖。
二,代碼。
RootViewController.h
#import <UIKit/UIKit.h>
@interface RootViewController : UIViewController
@end
RootViewController.m
#import "RootViewController.h"
#import "FirstViewController.h"
@interface RootViewController ()
@end
@implementation RootViewController
- (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.title=@"首頁";
self.view.backgroundColor=[UIColor redColor];
/* 過渡效果
fade //交叉淡化過渡(不支持過渡方向)
push //新視圖把舊視圖推出去
moveIn //新視圖移到舊視圖上面
reveal //將舊視圖移開,顯示下麵的新視圖
cube //立方體翻滾效果
oglFlip //上下左右翻轉效果
suckEffect //收縮效果,如一塊布被抽走(不支持過渡方向)
rippleEffect //滴水效果(不支持過渡方向)
pageCurl //向上翻頁效果
pageUnCurl //向下翻頁效果
cameraIrisHollowOpen //相機鏡頭打開效果(不支持過渡方向)
cameraIrisHollowClose //相機鏡頭關上效果(不支持過渡方向)
*/
/* 過渡方向
fromRight;
fromLeft;
fromTop;
fromBottom;
*/
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
CATransition *transition = [CATransition animation];
// 動畫時間控制
transition.duration = 0.3f;
//動畫的開始與結束的快慢
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
//是否代理
transition.delegate = self;
//此動畫執行完後會自動remove,預設值為true
transition.removedOnCompletion = NO;
//各種動畫效果
transition.type = kCATransitionMoveIn;
//動畫方向
transition.subtype = kCATransitionFromTop;
FirstViewController *viewCon = [[FirstViewController alloc]init];
[self.navigationController pushViewController:viewCon animated:NO];
// 想添加CA動畫的VIEW的層上添加此代碼
[self.navigationController.view.layer addAnimation:transition forKey:nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}