UINavigationItem外观不一致

时间:2018-10-11 15:37:56

标签: ios objective-c uiappearance

默认情况下,在我们的应用中,UINavigationBarItems具有以下外观

NSDictionary *atts = [NSDictionary dictionaryWithObjectsAndKeys: [UIColor clearColor], NSForegroundColorAttributeName, nil];
[[UIBarButtonItem appearance] setTitleTextAttributes:atts forState:UIControlStateNormal];
[[UIBarButtonItem appearance] setTitleTextAttributes:atts forState:UIControlStateHighlighted];

基本上,我们将标题设置为透明。

这会影响与UIImagePicker之类的其他组件的潜在集成,但是基本上,当我们显示图像选择器时,我们会回退这种外观。

NSDictionary *atts = [NSDictionary dictionaryWithObjectsAndKeys: [UIColor darkGrayColor], NSForegroundColorAttributeName, nil];
[[UIBarButtonItem appearance] setTitleTextAttributes:atts forState:UIControlStateNormal];
[[UIBarButtonItem appearance] setTitleTextAttributes:atts forState:UIControlStateHighlighted];

但是,如果在UITextView中我们具有链接或电子邮件,并且通过3D触摸,系统将显示“发送消息”或“添加到联系人”菜单,则该应用程序会显示透明按钮,从而使可用性很差

解决方法1

我们在viewWillDisappear中检测视图是否已弹出或由于其他组件(图像选择器,添加联系人,短信...)而被隐藏

- (void) viewWillDisappear:(BOOL)animated {
    BOOL isBeingRemoved = [self isMovingFromParentViewController] || self.isBeingDismissed;
    if (isBeingRemoved) {
        // Hidding the UINavigationBarItem title
        NSDictionary *atts = [NSDictionary dictionaryWithObjectsAndKeys: [UIColor clearColor], NSForegroundColorAttributeName, nil];
       [[UIBarButtonItem appearance] setTitleTextAttributes:atts forState:UIControlStateNormal];
       [[UIBarButtonItem appearance] setTitleTextAttributes:atts forState:UIControlStateHighlighted];

    } else {
        // Make visible the UINavigationBarItem title
        NSDictionary *atts = [NSDictionary dictionaryWithObjectsAndKeys: [UIColor darkGrayColor], NSForegroundColorAttributeName, nil];
       [[UIBarButtonItem appearance] setTitleTextAttributes:atts forState:UIControlStateNormal];
       [[UIBarButtonItem appearance] setTitleTextAttributes:atts forState:UIControlStateHighlighted];
    }
    [super viewWillDisappear:animated];
}

但是,这样做会更新应用程序的外观,并且应用程序标题不再透明。

解决方法2

我们尝试在viewWillAppear中应用透明对象,并在viewWillDisappear中将darkGray应用对象,并且适用于图像选择器,但不适用于其余应用程序。

解决方法3

我们也尝试在不使用viewWillDisappear外观的情况下设置darkGrayColor,但是没有用。

self.navigationcontroller.navigationbar.titletextattributes

有什么建议吗?

0 个答案:

没有答案