iOS7以上自訂一個navigationController,並沿用系統的側滑返回效果

來源:互聯網
上載者:User

標籤:

首先需要子類化一個navigationController的子類,在init方法中對定製nav的一些基本需求進行設定

 1 - (instancetype)initWithRootViewController:(UIViewController *)rootViewController 2 { 3     if (self = [super initWithRootViewController:rootViewController]) { 4         // 設定navigationBar的背景顏色,根據需要自己設定 5         self.navigationBar.barTintColor = redButtonColor; 6         // 設定navigationBar是否透明,不透明的話會使可用介面原點下移(0,0)點為導覽列左下角下方的那個點 7         self.navigationBar.translucent = NO; 8         // 設定navigationBar是不是使用系統預設返回,預設為YES 9         self.interactivePopGestureRecognizer.enabled = YES;10         // 建立一個顏色,便於之後設定顏色使用11         UIColor * color = [UIColor whiteColor];12         // 設定navigationBar元素的背景顏色,不包括title13         self.navigationBar.tintColor = color;14         // 設定navigationController的title的字型顏色15         NSDictionary * dict=[NSDictionary dictionaryWithObject:color forKey:NSForegroundColorAttributeName];16         self.navigationBar.titleTextAttributes = dict;17     }18     19     return self;20 }

因為這個導覽列是你自己自訂的,所以預設的側滑返回會失效,接下來要在viewDidLoad中從新遵循手勢的代理

- (void)viewDidLoad{    // 為self建立弱引用對象    __weak typeof (self) weakSelf = self;    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {        self.interactivePopGestureRecognizer.delegate = weakSelf;    }}

OK,完成

iOS7以上自訂一個navigationController,並沿用系統的側滑返回效果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.