有時(shí)候我們需要
1晦嵌、自定義navigationController push和pop界面切換動(dòng)畫(huà)
2、Push 拷姿、Pop 的時(shí)候更好的記錄層次
那就試著對(duì)UINavigationController Category一下吧
??Category的用途
在不創(chuàng)建繼承類(lèi)的情況下實(shí)現(xiàn)對(duì)已有類(lèi)的擴(kuò)展惭载。
簡(jiǎn)化類(lèi)的開(kāi)發(fā)工作(當(dāng)一個(gè)類(lèi)需要多個(gè)程序員協(xié)同開(kāi)發(fā)的時(shí)候,Category可以將同一個(gè)類(lèi)根據(jù)用途分別放在不同的源文件中响巢,從而便于程序員獨(dú)立開(kāi)發(fā)相應(yīng)的方法集合)描滔。
將常用的相關(guān)的方法分組。
關(guān)于push和pop界面切換動(dòng)畫(huà)
代碼如下:
UINavigationController+Animation.h
#import <UIKit/UIKit.h>
@interface UINavigationController (Animation)
- (void)pushViewController:(UIViewController *)controller withTransition:(UIViewAnimationTransition)transition;
- (UIViewController *)popViewControllerWithTransition:(UIViewAnimationTransition)transition;
@end
UINavigationController+Animation.m
- (void)pushViewController:(UIViewController *)controller withTransition:(UIViewAnimationTransition)transition {
[UIView beginAnimations:nil context:NULL];
[self pushViewController:controller animated:NO];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:transition forView:self.view cache:YES];
[UIView commitAnimations];
}
- (UIViewController *)popViewControllerWithTransition:(UIViewAnimationTransition)transition {
[UIView beginAnimations:nil context:NULL];
UIViewController *controller = [self popViewControllerAnimated:NO];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:transition forView:self.view cache:YES];
[UIView commitAnimations];
return controller;
}
So easy!!
關(guān)于動(dòng)畫(huà)補(bǔ)充一下:
UIViewAnimationTransition
// UIViewAnimationTransitionNone 不使用動(dòng)畫(huà)
// UIViewAnimationTransitionFlipFromLeft 從左向右旋轉(zhuǎn)翻頁(yè)
// UIViewAnimationTransitionFlipFromRight 從右向左旋轉(zhuǎn)翻頁(yè)踪古,與UIViewAnimationTransitionFlipFromLeft相反
// UIViewAnimationTransitionCurlUp 卷曲翻頁(yè)含长,從下往上
// UIViewAnimationTransitionCurlDown 卷曲翻頁(yè),從上往下
如果需要更多自定義的動(dòng)畫(huà)效果伏穆,也可以自己自定義哦
效果:
關(guān)于Push 拘泞、Pop 的時(shí)候更好的記錄層次
UINavigationController+NavManager
/**
* @brief 尋找Navigation中的某個(gè)viewcontroler對(duì)象
*
* @param className viewcontroler名稱(chēng)
*
* @return viewcontroler對(duì)象
*/
- (id)findViewController:(NSString*)className;
/**
* @brief 判斷是否只有一個(gè)RootViewController
*
* @return 是否只有一個(gè)RootViewController
*/
- (BOOL)isOnlyContainRootViewController;
/**
* @brief RootViewController
*
* @return RootViewController
*/
- (UIViewController *)rootViewController;
/**
* @brief 返回指定的viewcontroler
*
* @param className 指定viewcontroler類(lèi)名
* @param animated 是否動(dòng)畫(huà)
*
* @return pop之后的viewcontrolers
*/
- (NSArray *)popToViewControllerWithClassName:(NSString*)className animated:(BOOL)animated;
/**
* @brief pop n層
*
* @param level n層
* @param animated 是否動(dòng)畫(huà)
*
* @return pop之后的viewcontrolers
*/
- (NSArray *)popToViewControllerWithLevel:(NSInteger)level animated:(BOOL)animated;
項(xiàng)目傳送門(mén)
項(xiàng)目地址
https://github.com/SmileMee/SmileHelper.git
我是寫(xiě)代碼的凡,如有錯(cuò)誤枕扫,歡迎指正陪腌!??????