UITabBar 显示 UITabBarItem 图片忽略渲染模式 AlwaysOriginal [英] UITabBar displays UITabBarItem image ignoring rendering mode AlwaysOriginal

查看:16
本文介绍了UITabBar 显示 UITabBarItem 图片忽略渲染模式 AlwaysOriginal的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着 tvOS 9.1 和 Xcode 7.2 的发布,我的 UITabBarItem 图像显示不正确.在我的视图控制器中,我使用 UIImageRenderingMode.AlwaysOriginal 设置了带有图像的 tabBarItem.imagetabBarItem.selectedImage.

required init?(coder aDecoder: NSCoder) {super.init(编码器:aDecoder)self.tabBarItem.image = UIImage(named: "myTabImage")?.imageWithRenderingMode(.AlwaysOriginal)self.tabBarItem.selectedImage = UIImage(named: "myTabImageSelected")?.imageWithRenderingMode(.AlwaysOriginal)}

选中的图片显示正确,但未选中的图片显示为模板,即忽略其颜色信息.

两个图像都使用 tvOS 9.0 SDK 正确显示,但未选择的图像在 tvOS 9.1 中显示不正确.更糟糕的是,未选中的图像显示为黑色,标签栏背景也显示为黑色.

这是在 tvOS 9.0 上运行的相同代码

我怀疑这是 tvOS 9.1 的错误,但有没有人找到解决方法或看到我没有正确做的事情?

解决方案

这似乎是 tvOS 9.1 的 UITabBarController 实现中的一个错误.所以我最终写了我自己的替代品.在此期间,我添加了对超过 7 个标签栏项目的支持,使其在黑色背景下看起来很漂亮,并在其中一个标签上(也在黑色背景上)包括了一个搜索栏.这解决了我在构建第一个 tvOS 应用时遇到的许多困难.

With the release of tvOS 9.1 and Xcode 7.2, my UITabBarItem images are being displayed incorrectly. In my view controllers, I set the tabBarItem.image and tabBarItem.selectedImage with images using UIImageRenderingMode.AlwaysOriginal.

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)

    self.tabBarItem.image = UIImage(named: "myTabImage")?.imageWithRenderingMode(.AlwaysOriginal)
    self.tabBarItem.selectedImage = UIImage(named: "myTabImageSelected")?.imageWithRenderingMode(.AlwaysOriginal)
}

The selected image displays correctly, but the non-selected image displays as a template, that is, its color information is ignored.

Both images displayed correctly using the tvOS 9.0 SDK, but the non-selected image is displaying incorrectly in tvOS 9.1. To make matters worse, the non-selected images are being shown as black and the tab bar background is also black.

Here is the same code running on tvOS 9.0

I suspect this is a bug with tvOS 9.1, but has anyone found a workaround or see something that I am not doing correctly?

解决方案

It appears to definitely be a bug in the UITabBarController implementation for tvOS 9.1. So I ended up writing my own replacement. While at it, I added support for more than 7 tab bar items, made it look nice on a black background, and included a search bar on one of the tabs (also on a black background). This solves many of the difficulties I faced trying to build my first tvOS app.

Link to Github repository

这篇关于UITabBar 显示 UITabBarItem 图片忽略渲染模式 AlwaysOriginal的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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