当我推送 UIViewController 时,我在 iOS 11 上发现了一个奇怪的行为并更改 UINavigationBar颜色为透明。重要的是我正在使用 largeTitles .
我想将导航栏的红色更改为透明,效果很好。
但是,如果我点击 backButton,再次禁用透明样式和红色样式,就会发生不好的事情。 ViewController 上的 NavigationBar 不是红色但仍然是透明的。
正如@Menoor Ranpura 建议我添加另一行,它也设置了一个 backgroundColor在 UIViewController 中查看- 当您设置与 UINavigationBar 相同的颜色时,这是一个很好的解决方法.但是,这不是问题的解决方案,因为导航栏的大部分仍然是透明的。当您为背景设置不同的颜色时,您可以看到它。比如我设置的黄色。你可以在这里看到这个例子:
当 prefersLargeTitles 时,如何正确地将导航栏颜色从透明 更改为红色设置为 true ?
class ExampleTableTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "reuseID")
navigationController?.navigationBar.redNavigationBar()
title = "Red NavBar"
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
view.backgroundColor = .yellow
navigationController?.navigationBar.redNavigationBar()
}
}
//Transparent Navigation bar controller
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
title = "Transparent NavBar"
view.backgroundColor = .blue
self.navigationController?.navigationBar.prefersLargeTitles = true
}
override func viewWillAppear(_ animated: Bool) {
self.navigationController?.navigationBar.transparentNavigationBar()
}
}
extension UINavigationBar {
func redNavigationBar() {
setBackgroundImage(nil, for: .default)
shadowImage = nil
prefersLargeTitles = true
tintColor = .white
largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
barTintColor = .red
}
func transparentNavigationBar() {
setBackgroundImage(UIImage(), for: .default)
shadowImage = UIImage()
}
}
prefersLargeTitles 时一切正常设置为 false prefersLargeTitles 时一切正常设置为 true ,但是 navigationBar变化在非透明颜色之间。例如,如果在绿色 <-> 黄色->backgroundColor在 View 中。这不是解决方案,而是一种解决方法。 在这里您可以看到来自 XCode 的屏幕:
有趣的是,有一个东西叫做:_UINavigationBarLargeTitleView这是透明的。 如何访问?
您可以在这里找到示例项目:https://github.com/kamwysoc/LargeTitlesNavigationBarTransition
@Menoor Ranpura 建议的代码是一种解决方法。设置相同的 backgroundColor 不是解决方案在 UIViewController查看 UINavigationBar拥有。但是,我走得更远,我将颜色更改为不同于 UINavigationBar 的颜色。 Controller 有。正如您在上面的 gif 中看到的,当 largeTitle出现时,导航栏变成黄色——这意味着它是透明的——因为我们能够看到 View 的黄色背景。
最佳答案
在viewWillAppear中调用greenNavigationBar()
override func viewWillAppear(_ animated: Bool)
{
view.backgroundColor = .red // this is kind of a workaround, However if you set color which will be different that `UINavigationBar` color you see that `largeTitle` is transparent because it shows a `backgroundColor` of a ViewController view.
navigationController?.navigationBar.greenNavigationBar()
title = "Green Title"
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Next", style: .plain, target: self, action: #selector(showTransparentViewController))
}
关于ios - UINavigationBar 颜色和透明之间的过渡 - 错误 [iOS 11],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49378844/
我构建了两个需要相互通信和发送文件的Rails应用程序。例如,一个Rails应用程序会发送请求以查看其他应用程序数据库中的表。然后另一个应用程序将呈现该表的json并将其发回。我还希望一个应用程序将存储在其公共(public)目录中的文本文件发送到另一个应用程序的公共(public)目录。我从来没有做过这样的事情,所以我什至不知道从哪里开始。任何帮助,将不胜感激。谢谢! 最佳答案 无论Rails是什么,几乎所有Web应用程序都有您的要求,大多数现代Web应用程序都需要相互通信。但是有一个小小的理解需要你坚持下去,网站不应直接访问彼此
我想在一个没有Sass引擎的类中使用Sass颜色函数。我已经在项目中使用了sassgem,所以我认为搭载会像以下一样简单:classRectangleincludeSass::Script::FunctionsdefcolorSass::Script::Color.new([0x82,0x39,0x06])enddefrender#hamlengineexecutedwithcontextofself#sothatwithintemlateicouldcall#%stop{offset:'0%',stop:{color:lighten(color)}}endend更新:参见上面的#re
在Cooper的书BeginningRuby中,第166页有一个我无法重现的示例。classSongincludeComparableattr_accessor:lengthdef(other)@lengthother.lengthenddefinitialize(song_name,length)@song_name=song_name@length=lengthendenda=Song.new('Rockaroundtheclock',143)b=Song.new('BohemianRhapsody',544)c=Song.new('MinuteWaltz',60)a.betwee
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
我正在检查一个Rails项目。在ERubyHTML模板页面上,我看到了这样几行:我不明白为什么不这样写:在这种情况下,||=和ifnil?有什么区别? 最佳答案 在这种特殊情况下没有区别,但可能是出于习惯。每当我看到nil?被使用时,它几乎总是使用不当。在Ruby中,很少有东西在逻辑上是假的,只有文字false和nil是。这意味着像if(!x.nil?)这样的代码几乎总是更好地表示为if(x)除非期望x可能是文字false。我会将其切换为||=false,因为它具有相同的结果,但这在很大程度上取决于偏好。唯一的缺点是赋值会在每次运行
我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的
如何使用Ruby的默认Curses库获取颜色?所以像这样:puts"\e[0m\e[30;47mtest\e[0m"效果很好。在浅灰色背景上呈现漂亮的黑色。但是这个:#!/usr/bin/envrubyrequire'curses'Curses.noecho#donotshowtypedkeysCurses.init_screenCurses.stdscr.keypad(true)#enablearrowkeys(forpageup/down)Curses.stdscr.nodelay=1Curses.clearCurses.setpos(0,0)Curses.addstr"Hello
状态:我正在构建一个应用程序,其中需要一个可供用户选择颜色的字段,该字段将包含RGB颜色代码字符串。我已经测试了一个看起来很漂亮但效果不佳的。它是“挑剔的颜色”,并托管在此存储库中:https://github.com/Astorsoft/picky-color.在这里我打开一个关于它的一些问题的问题。问题:请建议我在Rails3应用程序中使用一些颜色选择器。 最佳答案 也许页面上的列表jQueryUIDevelopment:ColorPicker为您提供开箱即用的产品。原因是jQuery现在包含在Rails3应用程序中,因此使用基
运行bundleinstall后出现此错误:Gem::Package::FormatError:nometadatafoundin/Users/jeanosorio/.rvm/gems/ruby-1.9.3-p286/cache/libv8-3.11.8.13-x86_64-darwin-12.gemAnerroroccurredwhileinstallinglibv8(3.11.8.13),andBundlercannotcontinue.Makesurethat`geminstalllibv8-v'3.11.8.13'`succeedsbeforebundling.我试试gemin
1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里