亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

學(xué)習(xí)iOS自定義導(dǎo)航控制器UINavigationController

 更新時(shí)間:2016年09月30日 10:48:49   作者:vbirdbest  
這篇文章主要為大家詳細(xì)介紹了iOS自定義導(dǎo)航控制器UINavigationController,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

自定義導(dǎo)航控制器: 將導(dǎo)航控制器中通用的部分拿出來(lái)統(tǒng)一設(shè)置

1、一般導(dǎo)航條標(biāo)題的字體setTitleTextAttribute和背景顏色setBackgroundImage都是統(tǒng)一的,可以在load方法中使用appearanceWhenContainedIn統(tǒng)一設(shè)置
2、一般導(dǎo)航條的返回按鈕需要自定義,一般除了棧底控制器有導(dǎo)航條,其他控制器都需要隱藏底部的條,可以重寫(xiě)pushViewController:animated:方法,在該方法中實(shí)現(xiàn)該功能
3、導(dǎo)航控制器右滑返回效果(觸摸屏幕的任意一點(diǎn),向右滑動(dòng)返回)

UIViewController 
 --navigationItem 
   leftBarButtonItem | leftBarButtonItems
   NSString title | UIView titleView
   rightBarButtonItem | rightBarButtonItems
   backBarButtonItem

#import "BWNavigationController.h"
#import "UIBarButtonItem+Item.h"

@interface BaseNavigationController () <UIGestureRecognizerDelegate>

@end

@implementation BWNavigationController

+ (void)load {
  [super load];
  UINavigationBar *navigationBar = [UINavigationBar appearanceWhenContainedIn:self, nil];

  NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  dict[NSFontAttributeName] = [UIFont boldSystemFontOfSize:20];
  [navigationBar setTitleTextAttributes:dict];

  [navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackgroundWhite"] forBarMetrics:UIBarMetricsDefault];
}

- (void)viewDidLoad {
  [super viewDidLoad];
  // 屏幕邊緣滑動(dòng)(只能在屏幕的邊緣才能觸發(fā)該手勢(shì),不能在屏幕的任意一點(diǎn)觸發(fā)該手勢(shì))
  UIScreenEdgePanGestureRecognizer *edgePanGestureRecognizer = (UIScreenEdgePanGestureRecognizer *)self.interactivePopGestureRecognizer;

  // 滑動(dòng)手勢(shì)(禁用系統(tǒng)自帶的屏幕邊緣滑動(dòng)手勢(shì),使用自定義的滑動(dòng)手勢(shì)目的就是達(dá)到觸摸屏幕上的任意一點(diǎn)向右滑動(dòng)都能實(shí)現(xiàn)返回的效果)
  UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:edgePanGestureRecognizer.delegate action:@selector(handleNavigationTransition:)];
  panGestureRecognizer.delegate = self;
  [self.view addGestureRecognizer:panGestureRecognizer];

  // 禁用系統(tǒng)的屏幕邊緣滑動(dòng)手勢(shì)
  edgePanGestureRecognizer.enabled = NO;
}

// 是否允許觸發(fā)手勢(shì),如果是根視圖控制器則不需要
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
  return self.childViewControllers.count > 1;
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
  // 統(tǒng)一設(shè)置返回按鈕
  NSInteger count = self.childViewControllers.count;
  if (count > 0) {
    viewController.hidesBottomBarWhenPushed = YES;
    viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem backBarButtonItemWithImage:[UIImage imageNamed:@"navigationButtonReturn"] highlightImage:[UIImage imageNamed:@"navigationButtonReturnClick"] tagert:self action:@selector(back) title:@"返回"];
  }

  [super pushViewController:viewController animated:animated];
}

- (void)back {
  [self popViewControllerAnimated:YES];
}
@end

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論