工欲善其事,必先利其器系列之 UINavigationController Category

有時(shí)候我們需要

1、自定義navigationController push和pop界面切換動(dòng)畫
2、Push 、Pop 的時(shí)候更好的記錄層次

那就試著對(duì)UINavigationController Category一下吧

??Category的用途

  1.  在不創(chuàng)建繼承類的情況下實(shí)現(xiàn)對(duì)已有類的擴(kuò)展。
    
  2.  簡(jiǎn)化類的開發(fā)工作(當(dāng)一個(gè)類需要多個(gè)程序員協(xié)同開發(fā)的時(shí)候,Category可以將同一個(gè)類根據(jù)用途分別放在不同的源文件中,從而便于程序員獨(dú)立開發(fā)相應(yīng)的方法集合)。
    
  3.  將常用的相關(guān)的方法分組。
    

關(guān)于push和pop界面切換動(dòng)畫

代碼如下:

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)畫補(bǔ)充一下:

UIViewAnimationTransition

//    UIViewAnimationTransitionNone    不使用動(dòng)畫
//    UIViewAnimationTransitionFlipFromLeft    從左向右旋轉(zhuǎn)翻頁
//    UIViewAnimationTransitionFlipFromRight    從右向左旋轉(zhuǎn)翻頁,與UIViewAnimationTransitionFlipFromLeft相反
//    UIViewAnimationTransitionCurlUp    卷曲翻頁,從下往上
//    UIViewAnimationTransitionCurlDown    卷曲翻頁,從上往下

如果需要更多自定義的動(dòng)畫效果,也可以自己自定義哦

效果:


關(guān)于Push 、Pop 的時(shí)候更好的記錄層次

UINavigationController+NavManager

/**
 *  @brief  尋找Navigation中的某個(gè)viewcontroler對(duì)象
 *
 *  @param className viewcontroler名稱
 *
 *  @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類名
 *  @param animated  是否動(dòng)畫
 *
 *  @return pop之后的viewcontrolers
 */
- (NSArray *)popToViewControllerWithClassName:(NSString*)className animated:(BOOL)animated;
/**
 *  @brief  pop n層
 *
 *  @param level  n層
 *  @param animated  是否動(dòng)畫
 *
 *  @return pop之后的viewcontrolers
 */
- (NSArray *)popToViewControllerWithLevel:(NSInteger)level animated:(BOOL)animated;

項(xiàng)目傳送門
項(xiàng)目地址
https://github.com/SmileMee/SmileHelper.git


我是寫代碼的凡,如有錯(cuò)誤,歡迎指正!??????

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 15,045評(píng)論 4 61
  • Swift版本點(diǎn)擊這里歡迎加入QQ群交流: 594119878最新更新日期:18-09-17 About A cu...
    ylgwhyh閱讀 25,990評(píng)論 7 249
  • 1 白鴿在天上盤旋著,當(dāng)時(shí)秋天的陽光正好,鴿群從天空劃過時(shí),天空中閃著迷人的白光。這些小家伙居然在見了陌生人之...
    寶貝書蟲閱讀 471評(píng)論 0 0
  • 醒過來第一件事,吃 沒有昨日甜的感覺,依然不好吃。上稱59.1公斤,體重未減,脂肪33.9下降0.4
    潘潘_ef11閱讀 194評(píng)論 0 0
  • 就這樣一路走著,任時(shí)光無言流轉(zhuǎn),整個(gè)世界靜默著。 在漫長(zhǎng)的日子里,只是我們都習(xí)慣了聆聽,并為此感動(dòng)。 因而,我們也...
    3f4a1edff067閱讀 410評(píng)論 0 1

友情鏈接更多精彩內(nèi)容