我有一个视图作为 navigationController 的子视图放置,以填充整个显示。在此视图上,我有一个带有两个按钮的子视图。“删除并完成”。然后它还有一个日期选择器。datePicker 可以工作,但是,Remove 和 Done 按钮不会触发操作函数。
按钮:
var setButton: UIButton = {
var button = UIButton(type: .system)
button.setTitle("Done", for: .normal)
button.tintColor = .white
button.addTarget(self, action: #selector(handleReminderSetBtn), for: .touchUpInside)
return button
}()
var cancelButton: UIButton = {
var button = UIButton(type: .system)
button.setTitle("Remove", for: .normal)
button.tintColor = .white
button.addTarget(self, action: #selector(handleReminderCancelBtn), for: .touchUpInside)
return button
}()
Run Code Online (Sandbox Code Playgroud)
导航控制器中的主要 blackView:
viewOverLay.addSubview(cardreminder1)
viewOverLay.frame = CGRect(x: 0, y: 0, width: screenSize.width, height: screenSize.height)
viewOverLay.backgroundColor = UIColor.black.withAlphaComponent(0.3)
self.navigationController?.view.addSubview(viewOverLay)
Run Code Online (Sandbox Code Playgroud)
CardReminder1 是 UIView,我有两个按钮。
我认为这两个按钮的 addTarget 方法中的目标存在一些问题。可能是什么问题?
我有一个tabBar. 它的每个选项卡ViewControllers都嵌入在各自的NavigationControllers.
等级制度:
Tabbarcontroller--> NavigationController--> VC1 --> VC2 -->...VCn(对于tab1)
当我单击推送通知时,我必须重定向到其中一个视图控制器说 VC2。我使用的代码如下。
let navigationController = UINavigationController()
let storyboard = UIStoryboard.init(name: "Main", bundle: Bundle.main)
if let chatViewController = storyboard.instantiateViewController(withIdentifier: "chatViewController") as? ChatViewController {
navigationController.viewControllers = [chatViewController]
window?.rootViewController = navigationController
}
Run Code Online (Sandbox Code Playgroud)
通过使用它,我被重定向到相应的ViewController. 但是,我无法回到tabBar. 那么是否有可能以允许我返回标签栏的方式重定向,从而提供与 UI 中相同的层次结构?
编辑:
下图显示了我的布局。
我想完成以下工作:
当用户点击推送通知时,应用程序应被定向到 VC-B。*如果 VC-B 已经在导航堆栈的顶部,它不应该为 VC-B 创建新对象并添加到导航堆栈。
如果应用程序已终止并且用户点击通知,则应打开 VC-B。
为了确定应用程序是否已终止,我设置了一个标志:
func applicationWillTerminate(_ application: UIApplication) {
UserDefaults.standard.set(true, forKey: UserDefaultsKey.isTerminated)
}
Run Code Online (Sandbox Code Playgroud)
该标志在 didFinishLaunchingWithOptions 函数结束时设置为 false。 …
uitabbarcontroller uinavigationcontroller push-notification ios swift
我想向导航栏添加一个横幅,但要增加它的高度。我想复制 Apple Music 应用中艺术家页面的设计和行为:

它的行为就像普通的大标题一样,除了它已向下移动之外,它UIImageView后面有一个粘性标签,并且当用户向下滚动足够远时它会返回其背景。您可以启动Apple Music,搜索艺术家并前往他们的页面亲自尝试。
我尝试了很多事情,例如在 上设置框架UINavigationBarLargeTitleView,以及此答案中的代码: https: //stackoverflow.com/a/49326161/5544222
我已经使用以下代码掌握了UINavigationBarLargeTitleView它:UILabel
func setLargeTitleHeight() {
if let largeTitleView = self.getLargeTitleView() {
if let largeTitleLabel = self.getLargeTitleLabel(largeTitleView: largeTitleView) {
// Set largeTitleView height.
}
}
}
func getLargeTitleView() -> UIView? {
for subview in self.navigationBar.subviews {
if NSStringFromClass(subview.classForCoder).contains("UINavigationBarLargeTitleView") {
return subview
}
}
return nil
}
func getLargeTitleLabel(largeTitleView: UIView) -> UILabel? {
for subview in largeTitleView.subviews {
if subview.isMember(of: UILabel.self) {
return (subview as! UILabel) …Run Code Online (Sandbox Code Playgroud) 我正在尝试将视图控制器嵌入到导航视图控制器中,以便获得导航栏和所有其他内容,例如后退按钮。我想以编程方式完成它。
我需要将 UIParallaxDimmingView 设为白色或透明。
vc1 的白色背景受到此 UIParallaxDimmingView 的影响,使其在动画结束后过渡到 vc2 时变成浅灰色,vc2 获得其白色背景。
我进行了一项研究,发现了这段代码,但对我不起作用。
func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
if (navigationController.viewControllers.count > 1)
{
self.navigationController?.interactivePopGestureRecognizer?.delegate = self
navigationController.interactivePopGestureRecognizer?.isEnabled = true;
}
else
{
self.navigationController?.interactivePopGestureRecognizer?.delegate = nil
navigationController.interactivePopGestureRecognizer?.isEnabled = false;
}
}
Run Code Online (Sandbox Code Playgroud)
神秘的_UIParallaxDimmingView。它是什么?
iOS 应用程序在 PushViewController 上冻结
更新 这是最初的问题如何在弹出的 UIViewController 中删除 UIParallaxDimmingView?
我创建了一个自定义UINavigationController如下-
class NavigationViewController: UINavigationController {
override init(rootViewController: UIViewController) {
super.init(rootViewController: rootViewController)
setup()
}
required init?(coder aDecoder: NSCoder) {
return nil
}
func setup() {
}
}
Run Code Online (Sandbox Code Playgroud)
我使用上面的导航控制器如下-
let viewController = NavigationViewController(rootViewController: UIViewController())
present(viewController, animated: true)
Run Code Online (Sandbox Code Playgroud)
上面的代码在 iOS 13 中按预期工作,但在 iOS 12 中失败并出现以下错误
致命错误:对类“appName.NavigationViewController”使用未实现的初始化程序“init(nibName:bundle:)”
添加以下初始化程序可以解决问题
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}
Run Code Online (Sandbox Code Playgroud)
谁能指出为什么上面的初始化程序在 iOS 13 中不需要,但在 iOS 12 中需要?
当用户选择不同的主题样式时,我需要更改导航栏背景颜色。
但奇怪的是,用户选择“深色”模式后,进入后台,然后回到前台,如果用户想改回“浅色”模式,导航栏仍然是黑色风格,有一个“_UIVisualEffectBackdropView”保持黑暗。
但如果用户在进入后台之前选择“Light”模式,则一切正常。
我该如何修复这个错误?下面是代码和图片:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
switch indexPath.row {
case 0:
self.changeToLightColor()
default:
self.changeToDarkColor()
}
}
private func changeToLightColor() {
self.navigationController?.navigationBar.barStyle = .default
let textAttribute = [NSAttributedString.Key.foregroundColor: UIColor.systemBlue]
self.navigationController?.navigationBar.titleTextAttributes = textAttribute
}
private func changeToDarkColor() {
self.navigationController?.navigationBar.barStyle = .black
let textAttribute = [NSAttributedString.Key.foregroundColor: UIColor.systemGreen]
self.navigationController?.navigationBar.titleTextAttributes = textAttribute
}
Run Code Online (Sandbox Code Playgroud)
非常感谢您的帮助和提前答复!
我有一个UINavigationController它的navigationBar配置为prefersLargeTitles = true和isTranslucent = false。
导航堆栈中的第一个视图控制器是 a ,UITableViewVontroller其navigationItem配置为largeTitleDisplayMode = .always。如果我推送另一个视图控制器并largeTitleDisplayMode = .never再次弹出它,则第一个视图控制器处于大标题折叠的状态。我必须向上滚动才能再次放大标题。
这是iOS 14故意的行为吗?有没有办法恢复大标题?
isTranslucent编辑:我刚刚意识到,该行为与导航栏的属性相关。
我想根据屏幕内容更改状态栏样式。对于较暗的屏幕,状态栏内容应为白色。对于较浅的屏幕,状态栏内容应为黑色。
看来该问题仅发生在 iOS 15 设备上。
下面的屏幕截图比较了 iOS 15.2 和 iOS 14.5 上的相同用例
正如您所看到的,即使导航栏样式设置为“黑色”,状态栏样式也是默认的
class ViewAController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// setup views ...
}
// setting navigation bar style doesn't work iOS 15. Needed to set UINavigationAppearance()
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.navigationBar.barTintColor = .white
self.navigationController?.navigationBar.barStyle = .default
self.navigationController?.navigationBar.titleTextAttributes = [.font: UIFont.boldSystemFont(ofSize: 18), .foregroundColor: UIColor.black]
if #available(iOS 15, *) {
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = .white
appearance.shadowImage = UIImage()
appearance.shadowColor = .clear
appearance.titleTextAttributes …Run Code Online (Sandbox Code Playgroud) uikit uinavigationcontroller swift uinavigationbarappearance ios15
更新 Xcode 后,我在控制台中看到以下消息:
[Assert] UINavigationBar decoded as unlocked for UINavigationController, or navigationBar delegate set up incorrectly. Inconsistent configuration may cause problems.
Run Code Online (Sandbox Code Playgroud)
我在导航控制器场景中拥有的所有数据都不会显示。我尝试将其放置到 SceneDelegate,但没有帮助:
self.window?.rootViewController = navigationVC
self.window?.makeKeyAndVisible()
Run Code Online (Sandbox Code Playgroud)
我应该怎么做才能解决这个问题?