UINavigationController

// 1.设置导航条的背题图片 --- 设置全局

    UINavigationBar *navBar = [UINavigationBar appearance];

    [navBar setBackgroundImage:[UIImage imageNamed:@"NavBar"] forBarMetrics:UIBarMetricsDefault];

    

    // 2.UIApplication设置状态栏的样式

    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;

        // 3.设置导航条标题的字体和颜色

    NSDictionary *titleAttr = @{

                                NSForegroundColorAttributeName:[UIColor whiteColor],

                                NSFontAttributeName:[UIFont systemFontOfSize:24]

                                };

    [navBar setTitleTextAttributes:titleAttr];

//tintColor是用于导航条的所有Item

//设置透明的Navigationbar

  [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:0];

    //    让黑线消失的方法

   self.navigationController.navigationBar.shadowImage=[UIImage new];    navBar.tintColor = [UIColor whiteColor];

      UIBarButtonItem *navItem = [UIBarButtonItem appearance];

 //设置Item的字体大小

    [navItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18]} forState:UIControlStateNormal];

#pragma mark 导航控制器的子控制器被pop[移除]的时候会调用

-(UIViewController *)popViewControllerAnimated:(BOOL)animated{

    return [super popViewControllerAnimated:animated];

}

#pragma mark 导航控制器的子控制器被push 的时候会调用 当调用super pushViewController这个父类方法就会底层就会压栈  因此它的Controllers是0,这个方法就可以判断是不是跟控制器 在它方法之前就可以判断  栈顶控制器不能够设置navigationItem.leftBarButton的属性

-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{

    //设置 push 新控制器的时候 隐藏Tabbar

    viewController.hidesBottomBarWhenPushed = YES;

    return [super pushViewController:viewController animated:animated];

}

//自定义导航栏中title的image和文件的位置

-(id)initWithCoder:(NSCoder *)aDecoder{

    if (self = [super initWithCoder:aDecoder]) {

        //设置图片的显示样式

        self.imageView.contentMode = UIViewContentModeCenter;

    }

     return self;

  }

 

//设置标题的位置

-(CGRect)titleRectForContentRect:(CGRect)contentRect{

 

    CGFloat titleW = contentRect.size.width - ImageW;

    CGFloat titleH = contentRect.size.height;

    return CGRectMake(0, 0, titleW, titleH);

}

//设置图片的位置

-(CGRect)imageRectForContentRect:(CGRect)contentRect{

    CGFloat imageW = ImageW;

    CGFloat imageH = contentRect.size.height;

    CGFloat imageX = contentRect.size.width - ImageW;

    //self.imageView.contentMode = UIViewContentModeCenter;

#warning 在此方法,UIButton的子控件都是空,不能在此地设置图片的显示样式

    

    //NSLog(@"%@",self.imageView);

    return CGRectMake(imageX, 0, imageW, imageH);

 

}

  self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(btnClick)];

 //present出来的类型

 CityChangeController * cityChangeController=[CityChangeController new];
    UINavigationController * nav=[[UINavigationController alloc]initWithRootViewController:cityChangeController];
    nav.modalPresentationStyle=UIModalPresentationFormSheet;
    [self presentViewController:nav animated:YES completion:nil];
//设置全局滑动导航 

UIGestureRecognizerDelegate

- (void)viewDidLoad {

    [super viewDidLoad];

    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self.interactivePopGestureRecognizer.delegate action:@selector(handleNavigationTransition:)];

       [self.view addGestureRecognizer:pan];

        // 控制手势什么时候触发,只有非根控制器才需要触发手势

    pan.delegate = self;

    // 禁止之前手势

    self.interactivePopGestureRecognizer.enabled = NO;

        // 假死状态:程序还在运行,但是界面死了.

      /*

     为什么导航控制器的手势不是全屏滑动 =>

     */

    

}

 

#pragma mark - UIGestureRecognizerDelegate

// 决定是否触发手势

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch

{

    return self.childViewControllers.count > 1;

}

 

posted @ 2016-06-28 22:08  阿法狗的世界  阅读(128)  评论(0)    收藏  举报