系统导航栏部分简单研究

来源:互联网 发布:数据统计分析书籍 编辑:程序博客网 时间:2024/05/07 04:06

在研究一下导航栏的时候,想要只用系统的动画,因而发现了一些问题

无法使用系统返回手势

添加delegate

__weak typeof (self) weakSelf =self;

    if ([selfrespondsToSelector:@selector(interactivePopGestureRecognizer)]) {

        self.interactivePopGestureRecognizer.delegate = weakSelf;

    }

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

{

    if ([selfrespondsToSelector:@selector(interactivePopGestureRecognizer)]) {

        self.interactivePopGestureRecognizer.enabled = animated;

    }

    

    [superpushViewController:viewControlleranimated:animated];

}

导航栏添加照片:

 [self.navigationBarsetBackgroundImage:[UIImageimageNamed:@"big4ads_banner02.png"]forBarMetrics:UIBarMetricsDefault];


一些ViewController手势冲突,添加delegate

  self.navigationController.delegate=self;


- (void)navigationController:(UINavigationController *)navigationController

       didShowViewController:(UIViewController *)viewController

                    animated:(BOOL)animated

{

    if ([viewControllerisKindOfClass:self.class]) {

        navigationController.interactivePopGestureRecognizer.enabled =NO;

    }elseif ([navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {

        navigationController.interactivePopGestureRecognizer.enabled =YES;

    }

}

iOS 7以上系统修改title文字大小,颜色

[[UINavigationBarappearance] setTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:[UIColorblackColor], NSForegroundColorAttributeName, [UIFontfontWithName:@ "HelveticaNeue-CondensedBlack"size:18.0],NSFontAttributeName, nil]];

导航栏UIBarButtonItem的修改

UIButton *clearButton = [[UIButtonalloc] initWithFrame:CGRectMake(0,0, 44,44)];

    clearButton.tintColor =[UIColorblackColor];

    UIImage *image =[UIImageimageNamed:@"delete"];

    image=[image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];

    [clearButton setImage:imageforState:UIControlStateNormal];

    [clearButton addTarget:selfaction:@selector(removeAllMessages:)forControlEvents:UIControlEventTouchUpInside];

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItemalloc] initWithCustomView:clearButton];

[[UIBarButtonItem appearance]setTintColor:[UIColor blackColor]];

上传一张结构图用来研究修改

系统返回按钮的修改需要在上一层修改。

self.navigationItem.backBarButtonItem=back;

系统返回按钮title会使用上一层的title,如果title长度过长,会使用系统语言的“返回”。


0 0
原创粉丝点击