#pragma - mark - 切换window RootViewController
- (IBAction)loginBtn:(UIButton *)sender {
AppDelegate* aud = (AppDelegate*)[UIApplication sharedApplication].delegate;
TJTabbarController* tabVc = [[TJTabbarController alloc] init];
[UIView transitionFromView:self.view
toView:tabVc.view
duration:1.0f
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:^(BOOL finished) {
aud.window.rootViewController = tabVc;
}];
}
UIWindow*window= aud.window;//[UIApplication sharedApplication].keyWindow;
[UIView transitionWithView:window duration:1.0 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
//self.view.transform = CGAffineTransformMakeScale(1.5, 1.5);
//self.view.alpha=0.8;
window.rootViewController=aud.tab;
}completion:^(BOOL finished){
// [UIView transitionWithView:window duration:1.0 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^
// {
//
// } completion:^(BOOL finished)
// {
//
// }];
}];
NavigationController 转场动画
CATransition *animation = [CATransition animation]; //创建一个转场动画。
[animation setType:@"cube"];//动画类型
//animation.type = kCATransitionPush;//较常用(推出效果)
//animation.type = kCATransitionReveal;//较常用(移走效果)
//animation.type = kCATransitionMoveIn;//较常用 (覆盖效果)
/*
fademoveIn push reveal和系统的四种一样
pageCurl 向上翻一页
pageUnCurl 向下翻一页
rippleEffect 滴水效果
suckEffect 收缩效果,如一块布被抽走
cube alignedCube 立方体效果
flip alignedFlip oglFlip 翻转效果
rotate 旋转
cameraIris cameraIrisHollowOpen cameraIrisHollowClose 相机
*/
[animation setDuration:1.0f];//动画时间
[animation setSubtype:kCATransitionFromTop]; //动画方向可设置 上 下 左 右 4个方向
//在这1秒内动画是均匀的效果
// [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
_secondController=[SecondViewController new];
[self.navigationController.view.layer addAnimation:animation forKey:nil];
[self.navigationController pushViewController:_secondController animated:YES];
//方式2:效果同上
[self.navigationController.view.layer addAnimation:animation forKey:@"aaa"];
[self.navigationController pushViewController:dvc animated:NO];以动画方式推出新页面
View 转场动画
//
// ViewController.m
// CATransition
//
// Created by 李泽鲁 on 14/12/12.
// Copyright (c) 2014年 李泽鲁. All rights reserved.
//
#define IMAGE1 @"01.jpg"
#define IMAGE2 @"02.jpg"
#define DURATION 0.7f
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic, assign) int subtype;
@end
typedef enum : NSUInteger {
Fade = 1, //淡入淡出
Push, //推挤
Reveal, //揭开
MoveIn, //覆盖
Cube, //立方体
SuckEffect, //吮吸
OglFlip, //翻转
RippleEffect, //波纹
PageCurl, //翻页
PageUnCurl, //反翻页
CameraIrisHollowOpen, //开镜头
CameraIrisHollowClose, //关镜头
CurlDown, //下翻页
CurlUp, //上翻页
FlipFromLeft, //左翻转
FlipFromRight, //右翻转
} AnimationType;
@implementation ViewController
- (void)viewDidLoad {
_subtype = 0;
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self addBgImageWithImageName:IMAGE2];
}
- (IBAction)tapButton:(id)sender {
UIButton *button = sender;
AnimationType animationType = button.tag;
NSString *subtypeString;
switch (_subtype) {
case 0:
subtypeString = kCATransitionFromLeft;
break;
case 1:
subtypeString = kCATransitionFromBottom;
break;
case 2:
subtypeString = kCATransitionFromRight;
break;
case 3:
subtypeString = kCATransitionFromTop;
break;
default:
break;
}
_subtype += 1;
if (_subtype > 3) {
_subtype = 0;
}
switch (animationType) {
case Fade:
[self transitionWithType:kCATransitionFade WithSubtype:subtypeString ForView:self.view];
break;
case Push:
[self transitionWithType:kCATransitionPush WithSubtype:subtypeString ForView:self.view];
break;
case Reveal:
[self transitionWithType:kCATransitionReveal WithSubtype:subtypeString ForView:self.view];
break;
case MoveIn:
[self transitionWithType:kCATransitionMoveIn WithSubtype:subtypeString ForView:self.view];
break;
case Cube:
[self transitionWithType:@"cube" WithSubtype:subtypeString ForView:self.view];
break;
case SuckEffect:
[self transitionWithType:@"suckEffect" WithSubtype:subtypeString ForView:self.view];
break;
case OglFlip:
[self transitionWithType:@"oglFlip" WithSubtype:subtypeString ForView:self.view];
break;
case RippleEffect:
[self transitionWithType:@"rippleEffect" WithSubtype:subtypeString ForView:self.view];
break;
case PageCurl:
[self transitionWithType:@"pageCurl" WithSubtype:subtypeString ForView:self.view];
break;
case PageUnCurl:
[self transitionWithType:@"pageUnCurl" WithSubtype:subtypeString ForView:self.view];
break;
case CameraIrisHollowOpen:
[self transitionWithType:@"cameraIrisHollowOpen" WithSubtype:subtypeString ForView:self.view];
break;
case CameraIrisHollowClose:
[self transitionWithType:@"cameraIrisHollowClose" WithSubtype:subtypeString ForView:self.view];
break;
case CurlDown:
[self animationWithView:self.view WithAnimationTransition:UIViewAnimationTransitionCurlDown];
break;
case CurlUp:
[self animationWithView:self.view WithAnimationTransition:UIViewAnimationTransitionCurlUp];
break;
case FlipFromLeft:
[self animationWithView:self.view WithAnimationTransition:UIViewAnimationTransitionFlipFromLeft];
break;
case FlipFromRight:
[self animationWithView:self.view WithAnimationTransition:UIViewAnimationTransitionFlipFromRight];
break;
default:
break;
}
static int i = 0;
if (i == 0) {
[self addBgImageWithImageName:IMAGE1];
i = 1;
}
else
{
[self addBgImageWithImageName:IMAGE2];
i = 0;
}
}
#pragma CATransition动画实现
- (void) transitionWithType:(NSString *) type WithSubtype:(NSString *) subtype ForView : (UIView *) view
{
//创建CATransition对象
CATransition *animation = [CATransition animation];
//设置运动时间
animation.duration = DURATION;
//设置运动type
animation.type = type;
if (subtype != nil) {
//设置子类
animation.subtype = subtype;//
}
//设置运动速度
animation.timingFunction = UIViewAnimationOptionCurveEaseInOut;
[view.layer addAnimation:animation forKey:@"animation"];
}
#pragma UIView实现动画
- (void) animationWithView : (UIView *)view WithAnimationTransition : (UIViewAnimationTransition) transition
{
[UIView animateWithDuration:DURATION animations:^{
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:transition forView:view cache:YES];
}];
}
#pragma 给View添加背景图
-(void)addBgImageWithImageName:(NSString *) imageName
{
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:imageName]];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end