z ?@在iOS7之前,View Controller的切換主要有4種:
1.Push/Pop,NavigationViewController
2. Present and dismis Modal
3. UITabBarController
4. addChildViewController(一般用于自定義的繼承于 UIViewController 的容器子類)
iOS5,調(diào)用- (void)transitionFromViewController:(UIViewController *)fromViewController toViewController:(UIViewController *)toViewController duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(5_0);
(1)前面3種方法這里就不多說(shuō)了,很常見(jiàn)的系統(tǒng)方法.至于第四種,我在前面文章-剖析網(wǎng)易標(biāo)簽欄的效果中已經(jīng)做了闡述,但是它提供的容器轉(zhuǎn)場(chǎng)動(dòng)畫只可以實(shí)現(xiàn)一些簡(jiǎn)單的UIView動(dòng)畫,但是難以重用,耦合高.
(2)關(guān)鍵的API:
A.動(dòng)畫控制器 (Animation Controllers) 遵從 UIViewControllerAnimatedTransitioning 協(xié)議,并且負(fù)責(zé)實(shí)際執(zhí)行動(dòng)畫。
B.交互控制器 (Interaction Controllers) 通過(guò)遵從 UIViewControllerInteractiveTransitioning 協(xié)議來(lái)控制可交互式的轉(zhuǎn)場(chǎng)。
C.轉(zhuǎn)場(chǎng)代理 (Transitioning Delegates) 根據(jù)不同的轉(zhuǎn)場(chǎng)類型方便的提供需要的動(dòng)畫控制器和交互控制器。
其中UINavigationControllerDelegate delegate 中新增了2個(gè)方法給NavigationController
UIViewControllerTransitioningDelegate 新增transitioningDelegate ?給Modal的Present和Dismis
UITabBarControllerDelegate ?delegate
- (id )tabBarController:(UITabBarController *)tabBarController
interactionControllerForAnimationController: (id )animationController NS_AVAILABLE_IOS(7_0);
- (id )tabBarController:(UITabBarController *)tabBarController
animationControllerForTransitionFromViewController:(UIViewController *)fromVC
toViewController:(UIViewController *)toVC ?NS_AVAILABLE_IOS(7_0);
D.轉(zhuǎn)場(chǎng)上下文 (Transitioning Contexts) 定義了轉(zhuǎn)場(chǎng)時(shí)需要的元數(shù)據(jù),比如在轉(zhuǎn)場(chǎng)過(guò)程中所參與的視圖控制器和視圖的相關(guān)屬性。 轉(zhuǎn)場(chǎng)上下文對(duì)象遵從 UIViewControllerContextTransitioning 協(xié)議,并且這是由系統(tǒng)負(fù)責(zé)生成和提供的。
E.轉(zhuǎn)場(chǎng)協(xié)調(diào)器(Transition Coordinators) 可以在運(yùn)行轉(zhuǎn)場(chǎng)動(dòng)畫時(shí),并行的運(yùn)行其他動(dòng)畫。 轉(zhuǎn)場(chǎng)協(xié)調(diào)器遵從 UIViewControllerTransitionCoordinator 協(xié)議。
(3)新的API主要提供了2種VC切換的方式:
A.非交互式切換,即定義一種從一個(gè)VC到另一個(gè)VC的動(dòng)畫效果,切換的時(shí)候自動(dòng)播放,
B.交互式切換,這種方式同樣需要定義動(dòng)畫效果,只是這個(gè)動(dòng)畫效果會(huì)根據(jù)跟隨交互式手勢(shì)來(lái)切換VC并同時(shí)播放動(dòng)畫效果。iOS7提供了一個(gè)默認(rèn)的基于百分比的動(dòng)畫實(shí)現(xiàn) UIPercentDrivenInteractiveTransition,而且根據(jù)WWDC的說(shuō)明,最簡(jiǎn)單的實(shí)現(xiàn)交互式動(dòng)畫的方法就是通過(guò)繼承 UIPercentDrivenInteractiveTransition。
原文:http://blog.csdn.net/hmt20130412/article/details/39079905