Ios轉場動畫,type動畫類型,跳轉控制器動畫

轉場動畫是針對view圖層的動畫ide

#import "DYViewController.h"

@interface DYViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@property (nonatomic, assign) int index;

@end

@implementation DYViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
 
    _index = 1;
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    _index++;
    
    if (_index == 10) {
        _index = 1;
    }
    NSString *fileName = [NSString stringWithFormat:@"%d",_index];
    _imageView.image = [UIImage imageNamed:fileName];
    
    CATransition *anim = [CATransition animation];
    
    anim.type = @"pageCurl";
    
    anim.subtype = kCATransitionFromLeft;
    anim.startProgress = 0.5;
    
    anim.duration = 2;
    
    [_imageView.layer addAnimation:anim forKey:nil];
}

視圖控制器直接切換動畫動畫

只須要在window的layer上添加轉場動畫便可實現atom

@interface KKTestController ()

@end

@implementation KKTestController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor redColor];
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
    btn.backgroundColor  = [UIColor yellowColor ];
    [btn addTarget:self action:@selector(testA:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
}


-(void)testA:(id)sender {
    KKTabBarController *test = [[KKTabBarController alloc] init];
    
    CATransition *anim = [CATransition animation];
    
    anim.type = @"oglFlip";
    
    anim.subtype = kCATransitionFromRight;
    
    anim.duration = 2;
 
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    
    [window.layer addAnimation:anim forKey:nil];
    window.rootViewController = test;

    
    
    
}
屬性解析:
type:動畫過渡類型
subtype:動畫過渡方向
startProgress:動畫起點(在總體動畫的百分比)
endProgress:動畫終點(在總體動畫的百分比)


/*type屬性 過渡效果
 fade     //交叉淡化過渡(不支持過渡方向) kCATransitionFade
 push     //新視圖把舊視圖推出去  kCATransitionPushurl

 moveIn   //新視圖移到舊視圖上面   kCATransitionMoveIn
 reveal   //將舊視圖移開,顯示下面的新視圖  kCATransitionReveal
 cube     //立方體翻滾效果
 oglFlip  //上下左右翻轉效果
 suckEffect   //收縮效果,如一塊布被抽走(不支持過渡方向)
 rippleEffect //滴水效果(不支持過渡方向)
 pageCurl     //向上翻頁效果
 pageUnCurl   //向下翻頁效果
 cameraIrisHollowOpen  //相機鏡頭打開效果(不支持過渡方向)
 cameraIrisHollowClose //相機鏡頭關上效果(不支持過渡方向)
*/
   
/*subtype 過渡方向spa

 kCATransitionFromRight
 kCATransitionFromLeft
 kCATransitionFromBottom
code

相關文章
相關標籤/搜索