当我单击它时,UIBarButtonItem将始终突出显示 [英] UIBarButtonItem will be always highlight when I click it

查看:90
本文介绍了当我单击它时,UIBarButtonItem将始终突出显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = @"这是个bug?->";
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:68/255.0 green:155/255.0 blue:235/255.0 alpha:1.0];
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};

    UIBarButtonItem *rightItem0 = [[UIBarButtonItem alloc] initWithTitle:@"我会变灰" style:UIBarButtonItemStylePlain target:self action:@selector(recordButtonClick)];
    [rightItem0 setTintColor:[UIColor whiteColor]];

    self.navigationItem.rightBarButtonItems = @[rightItem0];
}

- (void)recordButtonClick{
    [self.navigationController pushViewController:[NextViewController new] animated:YES];
}

右上方的UIBarButtonItem始终突出显示:

The top right UIBarButtonItem always highlighted:

为什么右上方的UIBarButtonItem我会变灰"总是突出显示? 是iOS 11.2中的错误吗?

Why is the UIBarButtonItem "我会变灰" on the top right always highlighted? Is it a bug in iOS 11.2?

推荐答案

这是iOS 11.2中的错误吗?

Is it a bug in iOS 11.2?

是的.根视图控制器中的右栏按钮项存在一个iOS 11错误.当您按下一个下一个视图控制器并弹出时,右栏按钮项将变暗.

Yes. There's an iOS 11 bug with the right bar button item in the root view controller. When you push to the next view controller and pop back, the right bar button item is dimmed.

那是您在截屏视频中看到的错误.在您的代码中,您将右栏按钮项目的色调颜色设置为白色.最初,它是 白色.但是当您按下然后弹出时,它不再是白色的.

That is the bug seen in your screencast. In your code, you set the right bar button item's tint color to white. And initially, it is white. But when you push and then pop, it is no longer white.

我要做的是在视图控制器的viewWillAppear中解决此问题,如下所示:

What I do is work around this in the view controller's viewWillAppear, as follows:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    self.navigationController?.navigationBar.tintAdjustmentMode = .normal
    self.navigationController?.navigationBar.tintAdjustmentMode = .automatic
}

这篇关于当我单击它时,UIBarButtonItem将始终突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆