先上Demo 效果
XXTransition 是什么鬼悟衩?
經(jīng)歷過(guò)幾個(gè)公司,領(lǐng)導(dǎo)換了一波波栓拜,產(chǎn)品換了一波波座泳,App的轉(zhuǎn)場(chǎng)動(dòng)畫也是換了一波波,于是各種 AnimatedTransitioning幕与、 InteractiveTransition代碼也寫了一波波挑势。如果項(xiàng)目中用到多種轉(zhuǎn)場(chǎng)效果,那代碼目錄可能是像這樣的啦鸣。
每個(gè)效果都分別有對(duì)應(yīng)的實(shí)現(xiàn)了AnimatedTransitioning和InteractiveTransition邏輯的文件潮饱。
能不能簡(jiǎn)單點(diǎn)?方便的管理項(xiàng)目中用到的轉(zhuǎn)場(chǎng)動(dòng)畫诫给,方便的添加轉(zhuǎn)場(chǎng)效果香拉,同時(shí)也能滿足各種轉(zhuǎn)場(chǎng)效果的切換,手勢(shì)交互的切換中狂? Yes凫碌,u can ! 這正是XXTransition能幫你做到的,請(qǐng)為它轉(zhuǎn)身胃榕。
XXTransition 為嘛來(lái)到這世上盛险?
- 方便添加自定義轉(zhuǎn)場(chǎng)效果,將重心放在動(dòng)畫效果的實(shí)現(xiàn)上
- 自由管理項(xiàng)目中多種轉(zhuǎn)場(chǎng)動(dòng)畫勋又,轉(zhuǎn)場(chǎng)手勢(shì)的切換苦掘,(媽媽再也不用擔(dān)心惡心的需求啦)
- 對(duì)于原使用系統(tǒng)轉(zhuǎn)場(chǎng)的工程,集成后無(wú)需修改任何原代碼楔壤。
- 提供轉(zhuǎn)場(chǎng)動(dòng)畫庫(kù)鸟蜡。我會(huì)不斷添加樸實(shí)無(wú)華和牛嗶閃閃的轉(zhuǎn)場(chǎng)動(dòng)畫在代碼中,供你直接調(diào)用挺邀。這些效果揉忘,包括我自己親手和不是親手寫的,如有雷同端铛,別計(jì)較啦泣矛,都是分享啦,當(dāng)然如果有大牛小牛給我投稿禾蚕,我會(huì)很開(kāi)心噠您朽,也會(huì)在代碼中注釋出處噠。
XXTransition 該怎么跑起來(lái)?
安裝
Github地址:https://github.com/mh4u/XXTransition/
將XXTransition目錄文件拖到工程中即可
使用
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//啟動(dòng)XXTransition自定義轉(zhuǎn)場(chǎng)
[XXTransition startGoodJob:GoodJobTypeAll transitionDuration:0.3];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
RootVC *vc = [[RootVC alloc] init];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:vc];
return YES;
}
這樣一句話調(diào)用就可以開(kāi)始工作啦哗总!
Nav轉(zhuǎn)場(chǎng)
- 初階
+ (void)startGoodJob:(GoodJobType)goodJobType transitionDuration:(NSTimeInterval)duration;
該方法的第一個(gè)參數(shù)是枚舉值
typedef NS_OPTIONS(NSUInteger, GoodJobType) {
GoodJobTypeNavOnly = 1 << 0,
GoodJobTypeModalOnly = 1 << 1,
GoodJobTypeAll = GoodJobTypeNavOnly | GoodJobTypeModalOnly
};
可以設(shè)置只使用自定義Nav轉(zhuǎn)場(chǎng)還是Modal轉(zhuǎn)場(chǎng)几颜,或者全部使用。XXTransition會(huì)在提供的轉(zhuǎn)場(chǎng)效果中設(shè)定一個(gè)默認(rèn)的Nav轉(zhuǎn)場(chǎng)效果讯屈。如果你原先工程中使用的是系統(tǒng)的Nav轉(zhuǎn)場(chǎng)效果蛋哭,那恭喜你,現(xiàn)在不需要改其他代碼就已經(jīng)可以實(shí)現(xiàn)自定義轉(zhuǎn)場(chǎng)了哦(使用Modal轉(zhuǎn)場(chǎng)和Nav轉(zhuǎn)場(chǎng)有所區(qū)別涮母,往下看)谆趾。
如果你想換一個(gè)XXTransition提供的Nav轉(zhuǎn)場(chǎng),這樣設(shè)置就可以啦叛本。
//啟動(dòng)XXTransition自定義轉(zhuǎn)場(chǎng)
[XXTransition startGoodJob:GoodJobTypeAll transitionDuration:0.3];
//更改全局NavTransiton效果
[XXTransition setNavTransitonKey:XXTransitionAnimationNavPage];
可是按照PM的要求沪蓬,是一個(gè)全新的轉(zhuǎn)場(chǎng)效果怎么辦,得自己寫啦来候。XXTransition可以讓你專注于動(dòng)畫的實(shí)現(xiàn)跷叉,交互手勢(shì)都不用care
//添加自定義NavTransiton效果
NSString *someNBTransitionAnimation = @“someNBTransitionAnimation";
[XXTransition addPushAnimation:demoTransitionAnimationFragment animation:^(id<UIViewControllerContextTransitioning> transitionContext, NSTimeInterval duration) {
//Push動(dòng)畫邏輯
}];
[XXTransition addPopAnimation:demoTransitionAnimationFragment animation:^(id<UIViewControllerContextTransitioning> transitionContext, NSTimeInterval duration) {
//Pop動(dòng)畫邏輯
}];
//更改全局NavTransiton效果
[XXTransition setNavTransitonKey:someNBTransitionAnimation];
- 進(jìn)階
一般情況下,一個(gè)App只會(huì)用一種轉(zhuǎn)場(chǎng)效果营搅,但有講究有追求的話云挟,可能需要多種轉(zhuǎn)場(chǎng)效果配合不同交互手勢(shì)在不同VC互相push,pop時(shí)進(jìn)行切換,簡(jiǎn)單畫個(gè)圖你就明白了
你遇到過(guò)嗎剧防,遇到了麻煩給個(gè)贊或者星,表示同病相憐辫樱,沒(méi)遇到也麻煩給個(gè)星或者贊峭拘,因?yàn)槲矣龅搅耍屛腋惺艿侥愕臏嘏ㄊ睢E龅竭@種情況鸡挠,不要藍(lán)瘦,不用香菇搬男,看看XXTransition怎么解決拣展。
//啟動(dòng)XXTransition自定義轉(zhuǎn)場(chǎng)
[XXTransition startGoodJob:GoodJobTypeAll transitionDuration:0.3];
//更改全局NavTransiton效果
[XXTransition setNavTransitonKey:XXTransitionAnimationNavPage];
//注冊(cè)特殊ViewController的NavTransiton效果和返回手勢(shì)
[XXTransition registerPushViewController:[SinkVC class] forTransitonKey:XXTransitionAnimationNavSink];
[XXTransition registerPushViewController:[PageVC class] forTransitonKey:XXTransitionAnimationNavPage];
[XXTransition registerPopGestureType:XXPopGestureTypeFullScreen forViewController:[SinkVC class]];
[XXTransition registerPopGestureType:XXPopGestureTypeForbidden forViewController:[PageVC class]];
就這樣,OK啦缔逛。SinkVC和PageVC分別使用響應(yīng)的Nav轉(zhuǎn)場(chǎng)效果和返回手勢(shì)备埃,而其他VC則使用全局轉(zhuǎn)場(chǎng)效果
Modal轉(zhuǎn)場(chǎng)
Modal切換ViewController的XXTransition使用方法和Nav有所不同,要在需要Present的使用調(diào)用UIViewController+XXTransition.h定義的方法
- (void)xx_presentViewController:(UIViewController *)viewControllerToPresent makeAnimatedTransitioning:(void (^)(XXAnimatedTransitioning *transitioning))block completion:(void (^ __nullable)(void))completion
使用如下
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (indexPath.row == 0) {
SinkVC *vc =[[SinkVC alloc] init];
[self.navigationController pushViewController:vc animated:YES];
} else {
ModalVC *vc = [[ModalVC alloc] init];
//XXTransition Modal轉(zhuǎn)場(chǎng)
[self xx_presentViewController:vc makeAnimatedTransitioning:^(XXAnimatedTransitioning * _Nonnull transitioning) {
transitioning.duration = 0.5;
transitioning.animationKey = XXTransitionAnimationModalSink;
} completion:NULL];
}
}
如果你需要自己敲一個(gè)新的轉(zhuǎn)場(chǎng)動(dòng)畫褐奴,類似于Nav轉(zhuǎn)場(chǎng)中的自定義按脚,專注動(dòng)畫實(shí)現(xiàn),在下面兩個(gè)方法中實(shí)現(xiàn)動(dòng)畫邏輯
[XXTransition addPresentAnimation:demoTransitionAnimationModalSink animation:^(id<UIViewControllerContextTransitioning> transitionContext, NSTimeInterval duration) {
//Present 轉(zhuǎn)場(chǎng)邏輯
}];
[XXTransition addDismissAnimation:demoTransitionAnimationModalSink backGestureDirection:XXBackGesturePanDown animation:^(id<UIViewControllerContextTransitioning> transitionContext, NSTimeInterval duration) {
//Dismiss 轉(zhuǎn)場(chǎng)邏輯
}];
XXTransition 在dismiss的轉(zhuǎn)場(chǎng)交互中敦冬,支持下面幾中選擇
typedef NS_ENUM(NSInteger,XXBackGesture){
XXBackGestureNone, //禁用手勢(shì)
XXBackGesturePanLeft,
XXBackGesturePanRight,
XXBackGesturePanUp,
XXBackGesturePanDown,
};
最后
如果你在使用XXTransition過(guò)程中發(fā)現(xiàn)任何問(wèn)題辅搬,或是有任何建議,歡迎勾搭我脖旱。