ios開發控制器動畫

一、模態視圖動畫

1、通過modalTransitionStyle屬性來設置彈出模態視圖的轉場動畫,即過渡樣式

UIModalTransitionStyleCoverVertical // 底部滑入。
UIModalTransitionStyleFlipHorizontal // 水平翻轉。
UIModalTransitionStyleCrossDissolve // 交叉溶解。
UIModalTransitionStylePartialCurl // 翻頁。


2、設置彈出控制器的風格(即呈現樣式,最終顯示的樣子),通過modalPresentationStyle屬性來設置

//跳轉之後覆蓋整個屏幕,不透明
UIModalPresentationFullScreen = 0
     
//跳轉之後覆蓋整個屏幕,不透明
UIModalPresentationPageSheet
     
//跳轉之後覆蓋整個屏幕,不透明
UIModalPresentationFormSheet
     
//跳轉之後覆蓋當前內容(除導航欄和標籤欄部分),不透明
UIModalPresentationCurrentContext
     
//跳轉之後顯示自定製視圖(默認是覆蓋整個屏幕),可以透明
UIModalPresentationCustom
     
//跳轉之後覆蓋整個屏幕,可以透明
UIModalPresentationOverFullScreen
     
//跳轉之後覆蓋當前內容(除導航欄和標籤欄部分),可以透明
UIModalPresentationOverCurrentContext
     
//跳轉之後覆蓋整個屏幕,不透明
UIModalPresentationPopover

舉個栗子

TwoViewController *twoVc = [[TwoViewController alloc] init];

//把當前控制器作爲背景
self.definesPresentationContext = YES;

twoVc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

twoVc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
    
[self presentViewController:twoVc animated:YES completion:nil];

3、定製模態跳轉

TwoViewController *twoVc = [[TwoViewController alloc] init];

    //創建動畫
    CATransition * transition = [CATransition animation];
    
    //設置動畫類型(這個是字符串,可以搜索一些更好看的類型)
    transition.type = @"cube";
    
    //動畫出現類型,動畫的方向
    transition.subtype = @"fromCenter";
    
    //動畫時間
    transition.duration = 0.3;
    
    //移除當前window的layer層的動畫
    [self.view.window.layer removeAllAnimations];
    
    //將定製好的動畫添加到當前控制器window的layer層
    [self.view.window.layer addAnimation:transition forKey:nil];
    
    [self presentViewController:twoVc animated:NO completion:nil];

動畫類型type的其它參數

設置動畫的屬性
fade        交叉淡化過渡
push        新視圖把舊視圖推出去
moveIn      新視圖移到舊視圖上面
reveal      將舊視圖移開,顯示下面的新視圖
cube        立方體翻滾效果-----好
oglFlip     上下左右翻轉效果---好
suckEffect      收縮效果,如一塊布被抽走---好
rippleEffect    水滴效果-----好
pageCurl        向上翻頁效果
pageUnCurl      向下翻頁效果
cameraIrisHollowOpen        相機鏡頭打開效果
cameraIrisHollowClose       相機鏡頭關閉效果


二、自定義轉場動畫

有3種類型,需要用到如下三個協議:

1、UINavigationControllerDelegate - 自定義navigationController轉場動畫的時候

2、UITabBarControllerDelegate - 自定義tabbarController轉場動畫的時候

3、UIViewControllerTransitioningDelegate - 自定義present / dismiss的時候

後續研究,參考博客:

https://onevcat.com/2013/10/vc-transition-in-ios7/

http://www.jianshu.com/p/73e65b70340e

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章