是否可以在每次更改时在控制台中打印变量的值,最方便的方法是什么?
编辑:我想跟踪 UINavigationController 的控制器堆栈的值
我有一个有点令人困惑的问题。在我的应用程序中,我有一个工具栏,可以以编程方式换出按钮并正确调用关联的选择器。但是,当我将相同的技术应用于导航栏上的按钮时,它无法调用选择器。以下示例代码包含 2 组按钮(一组用于导航,一组用于工具栏)。尽管相同,但导航栏按钮上的选择器从未被调用。
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var toolbar: UIToolbar!
let navCancelButton = UIBarButtonItem(barButtonSystemItem: .cancel,
target: self,
action: #selector(toggleDelete))
let navTrashButton = UIBarButtonItem(barButtonSystemItem: .trash,
target: self,
action: #selector(toggleDelete))
let toolbarCancelButton = UIBarButtonItem(barButtonSystemItem: .cancel,
target: self,
action: #selector(toggleDelete))
let toolbarTrashButton = UIBarButtonItem(barButtonSystemItem: .trash,
target: self,
action: #selector(toggleDelete))
var isDeleting = false {
didSet {
navigationItem.rightBarButtonItem = isDeleting ? navCancelButton : navTrashButton
toolbar.items = isDeleting ? [toolbarCancelButton] : [toolbarTrashButton]
}
}
override func viewDidLoad() {
super.viewDidLoad()
isDeleting = …Run Code Online (Sandbox Code Playgroud) 我一直试图解决这个问题很长一段时间,但无法弄清楚。我有当前的设置:
在每个视图控制器中,我都隐藏了导航栏,如下所示:
self.navigationController?.setNavigationBarHidden(true, animated: true)
Run Code Online (Sandbox Code Playgroud)
问题是我在隐藏导航栏的视图控制器上松开了滑动手势。我需要启用动画并且不能使用:
self.navigationController?.navigationBar.isHidden = true
self.navigationController?.isNavigationBarHidden = true
Run Code Online (Sandbox Code Playgroud)
任何帮助都会很棒,因为我相信很多人都遇到过这个问题。谢谢!
uinavigationbar uinavigationcontroller uigesturerecognizer ios swift
我正在使用平移手势识别器来关闭 UINavigationController。我正在使用此处的代码,并进行了修改以适合我的 NavigationController,我还将手势识别器添加到容器视图内的实际 VC。
一切正常,除了当我向下滑动时,导航栏会在 y 值 > 0.0 时更改其位置。
我认为正在发生的是导航栏附加到顶部安全区域,当它离开顶部安全区域时,它会自动将自身调整到视图的顶部。
我怎么能简单地实现它,以便导航栏的大小要么延伸到顶部的安全区域下方,要么完全忽略它,而是限制它所在的视图?
以下是图片:
这是我用于 UINavigationController 的代码
//
// PannableViewController.swift
//
import UIKit
class PannableViewController: UINavigationController {
public var minimumVelocityToHide = 1500 as CGFloat
public var minimumScreenRatioToHide = 0.5 as CGFloat
public var animationDuration = 0.2 as TimeInterval
override func viewDidLoad() {
super.viewDidLoad()
// Listen for pan gesture
let panGesture = UIPanGestureRecognizer(target: self, action: #selector(onPan(_:)))
if let lastVC = self.childViewControllers.last {
lastVC.view.addGestureRecognizer(panGesture)
}
}
func slideViewVerticallyTo(_ y: …Run Code Online (Sandbox Code Playgroud) uinavigationbar uinavigationcontroller ios uipangesturerecognizer swift
在我的 iPhone 应用程序中,我有两个 NavigationC0nroller 背景颜色和标题颜色
我正在使用如下通用代码来更改背景颜色和标题颜色
@objc class Helper : NSObject{
class func restNavigationBarWithNavigationController(navigationController : UINavigationController , withColor : UIColor,isTranslucent : Bool )
{
navigationController.navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationController.navigationBar.shadowImage = UIImage()
navigationController.navigationBar.isTranslucent = isTranslucent
navigationController.view.backgroundColor = withColor
navigationController.navigationBar.backgroundColor = withColor
}
}
Run Code Online (Sandbox Code Playgroud)
我在视图控制器的 viewdidload 和 ViewWillAppear 中调用上面,如下所示
self.navigationController?.navigationBar.tintColor = .white
Helper.restNavigationBarWithNavigationController(navigationController:
self.navigationController!, withColor: .clear, isTranslucent: true)
Run Code Online (Sandbox Code Playgroud)
但是上面的代码不起作用如果我从白色弹出一个屏幕到红色标题&反之亦然。
请让我知道我在这里做错了什么。
任何想法或建议都会很棒。(仅供参考:我在 Objective-c 视图控制器中使用相同的代码库)
我有问题...我有两个 ViewControllers,我使用此代码从第一个 VC 传递到第二个
let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let newViewController = storyBoard.instantiateViewController(withIdentifier: "EVSignInViewController") as! EVSignInViewController
self.present(newViewController, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
问题是..我想在第二个 VC 上显示后退按钮。我已经尝试在 1st VC 上使用 Editor->Embed in-> Navigation controller。我也用这个
navigationController?.setNavigationBarHidden(false, animated: true)
navigationItem.backBarButtonItem = UIBarButtonItem(title:"", style:.plain, target:nil, action:nil)
Run Code Online (Sandbox Code Playgroud) 所以我试图通过像这样子类化它来创建一个UIBarButtonItem自定义UIView。
import UIKit
import SnapKit
class LocationManager: UIBarButtonItem {
let createdView = UIView()
lazy var currentCityLabel: UILabel = {
let currentCityLabel = UILabel()
currentCityLabel.text = "Philadelphia, PA"
guard let customFont = UIFont(name: "NoirPro-SemiBold", size: 20) else {
fatalError("""
Failed to load the "CustomFont-Light" font.
Make sure the font file is included in the project and the font name is spelled correctly.
"""
)
}
currentCityLabel.adjustsFontForContentSizeCategory = true
return currentCityLabel
}()
lazy var downArrow: UIImageView = { …Run Code Online (Sandbox Code Playgroud) 使用Navigation Drawer Activity 创建新项目后,构建并运行,该Activity 不起作用。它有许多片段,当从活动抽屉中选择它们时,它们应该更改为。打开抽屉,选择选择,只见:这是家片段。
在网上搜索了2个小时,答案不清楚。DrawerLayout 的 Z 顺序
我只是希望模板在您运行时能够实际工作。
我尝试在 UInavigation 控制器的导航栏按钮中设置 lottie 动画,但我不知道如何将动画设置为 UIbarButtons
我有以下几点:
var body: some View {
NavigationView {
VStack {
Text("Hello")
}.navigationBarTitle("Edit Profile", displayMode: .inline)
.background(NavigationConfiguration { nc in
nc.navigationBar.barTintColor = .red
nc.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.black]
})
}.navigationViewStyle(StackNavigationViewStyle())
}
Run Code Online (Sandbox Code Playgroud)
对于导航栏的配置,我有:
struct NavigationConfiguration: UIViewControllerRepresentable {
var configuration: (UINavigationController) -> Void = { _ in }
func makeUIViewController(context: UIViewControllerRepresentableContext<NavigationConfiguration>) -> UIViewController {
UIViewController()
}
func updateUIViewController(_ uiViewController: UIViewController, context: UIViewControllerRepresentableContext<NavigationConfiguration>) {
if let nc = uiViewController.navigationController {
self.configuration(nc)
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是由于某种原因,顶部状态栏被排除在外,并且没有对其应用颜色:
如何将红色也应用于导航栏上方的状态栏,我希望它是相同的颜色。
我试过下面的,但这失败了:
init() {
UINavigationBar.appearance().backgroundColor = .red
}
Run Code Online (Sandbox Code Playgroud) uinavigationbar uinavigationcontroller swift swiftui swiftui-navigationlink