我正在尝试制作一个透明的导航栏,但是当我将其设置为透明时,它看起来像这样......:
但像在 App Store 中一样透明和模糊,但有背景颜色。问题是导航 Controller 的背景颜色不像正常情况下在状态栏下。
我的代码:
self.navigationItem.title = "label"
self.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
self.navigationBar.shadowImage = UIImage()
self.navigationBar.isTranslucent = true
self.navigationBar.backgroundColor = UIColor.init(red: 255/255, green: 0, blue: 0, alpha: 0.7)
编辑:我有一个自定义类 UINavigationController 并且 View Controller 嵌入在 UINavigationController
Swift 3、Xcode 8.0 beta 5。
最佳答案
让我们把这个问题分解成几个部分。首先,您需要使用通过 UIBlurEffect 创建的 UIVisualEffectView 来获得您想要的模糊/透明效果。然后您需要弄清楚如何在导航栏中显示它,以便它填满整个导航栏和状态栏。
第 1 部分
我创建了 UIVisualEffectView 的子类以添加渐变。我们可以使用此 View 来创建所需的模糊/透明效果。
class GradientVisualEffectView: UIVisualEffectView {
private let gradient: CAGradientLayer = {
// You can tweak these colors and their alpha to get the desired gradient.
// You can also mess with the gradient's locations.
$0.colors = [
UIColor.white.withAlphaComponent(0.3).cgColor,
UIColor(red: 1, green: 0, blue: 0, alpha: 0.7).cgColor
]
return $0
} (CAGradientLayer())
override init(effect: UIVisualEffect?) {
super.init(effect: effect)
layer.addSublayer(gradient)
}
override func layoutSubviews() {
super.layoutSubviews()
// Make sure the gradient's frame always matches the blur effect.
gradient.frame = bounds
}
}
第 2 部分
现在我们需要在导航栏中使用这个 View 。我在嵌入 UINavigationController 的 UIViewController 中执行此操作。
override func viewDidLoad() {
super.viewDidLoad()
// Remove the nav bar's background
let navBar = navigationController!.navigationBar
navBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
navBar.backgroundColor = .clear
// Create the blur/transparent view. You can mess with styles here to get
// different effects.
let gradientBlur = GradientVisualEffectView(effect: UIBlurEffect(style: .light))
gradientBlur.translatesAutoresizingMaskIntoConstraints = false
navBar.addSubview(gradientBlur)
// Constrain the view so that it always matches the nav bar.
// The top constraint has a -20 constant so that it will extend above
// the nav bar to the status bar.
gradientBlur.leftAnchor.constraint(equalTo: navBar.leftAnchor).isActive = true
gradientBlur.topAnchor.constraint(equalTo: navBar.topAnchor, constant: -20).isActive = true
gradientBlur.rightAnchor.constraint(equalTo: navBar.rightAnchor).isActive = true
gradientBlur.bottomAnchor.constraint(equalTo: navBar.bottomAnchor).isActive = true
}
下面是我的模拟器的结果图片。您可以在图片的左上角看到一些模糊的文字,其中状态栏的白色部分看起来更暗。
关于ios - 导航栏颜色不在状态栏下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39108337/
我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0
我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢
我想在一个没有Sass引擎的类中使用Sass颜色函数。我已经在项目中使用了sassgem,所以我认为搭载会像以下一样简单:classRectangleincludeSass::Script::FunctionsdefcolorSass::Script::Color.new([0x82,0x39,0x06])enddefrender#hamlengineexecutedwithcontextofself#sothatwithintemlateicouldcall#%stop{offset:'0%',stop:{color:lighten(color)}}endend更新:参见上面的#re
当我的预订模型通过rake任务在状态机上转换时,我试图找出如何跳过对ActiveRecord对象的特定实例的验证。我想在reservation.close时跳过所有验证!叫做。希望调用reservation.close!(:validate=>false)之类的东西。仅供引用,我们正在使用https://github.com/pluginaweek/state_machine用于状态机。这是我的预订模型的示例。classReservation["requested","negotiating","approved"])}state_machine:initial=>'requested
我刚刚被困在这个问题上一段时间了。以这个基地为例:moduleTopclassTestendmoduleFooendend稍后,我可以通过这样做在Foo中定义扩展Test的类:moduleTopmoduleFooclassSomeTest但是,如果我尝试通过使用::指定模块来最小化缩进:moduleTop::FooclassFailure这失败了:NameError:uninitializedconstantTop::Foo::Test这是一个错误,还是仅仅是Ruby解析变量名的方式的逻辑结果? 最佳答案 Isthisabug,or
这里有一个很好的答案解释了如何在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返回它复制的字节数,但是当我还没有下
我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的
对于作为String#tr参数的单引号字符串文字中反斜杠的转义状态,我觉得有些神秘。你能解释一下下面三个例子之间的对比吗?我特别不明白第二个。为了避免复杂化,我在这里使用了'd',在双引号中转义时不会改变含义("\d"="d")。'\\'.tr('\\','x')#=>"x"'\\'.tr('\\d','x')#=>"\\"'\\'.tr('\\\d','x')#=>"x" 最佳答案 在tr中转义tr的第一个参数非常类似于正则表达式中的括号字符分组。您可以在表达式的开头使用^来否定匹配(替换任何不匹配的内容)并使用例如a-f来匹配一
我目前正在使用以下方法获取页面的源代码:Net::HTTP.get(URI.parse(page.url))我还想获取HTTP状态,而无需发出第二个请求。有没有办法用另一种方法做到这一点?我一直在查看文档,但似乎找不到我要找的东西。 最佳答案 在我看来,除非您需要一些真正的低级访问或控制,否则最好使用Ruby的内置Open::URI模块:require'open-uri'io=open('http://www.example.org/')#=>#body=io.read[0,50]#=>"["200","OK"]io.base_ur
如何使用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