标签: uinavigationcontroller

在 Swift 中子类化 UINavigationBar

我正在尝试创建一个自定义UINavigationBar类,然后使用将其设置为我的 NavigationBar 的Storyboard类。UINavigationController

这是我的班级的代码UINavigationBar:

class CustomNavBar: UINavigationBar {

    override func drawRect(rect: CGRect) {
        super.drawRect(rect)
        // Drawing code
        self.backgroundColor = UIColor.orangeColor()

        let myLabel = UILabel(frame: CGRect(x: 0, y: 4, width: 600, height: 36))
        myLabel.backgroundColor = UIColor.purpleColor()
        myLabel.textColor = UIColor.yellowColor()
        myLabel.text = "Custom NavBar!"

        self.addSubview(myLabel)
    }

}
Run Code Online (Sandbox Code Playgroud)

然后,在 Interface Builder 中,我使用 将Identity Inspector其设置为NavigationBar我的UINavigationController.

当我运行该应用程序时 - 它冻结了。它挂起LaunchScreen.xib并且不执行任何操作。

为什么要这么做?这样做的正确方法是什么?

subclass uinavigationbar uinavigationcontroller ios swift

5
推荐指数
1
解决办法
6399
查看次数

iOS 中有滑动返回手势的回调吗?

有时,当用户返回到上一个时UIViewController,我想做点什么。

如果用户单击 中的后退按钮UINavigationBar,我可以捕获该事件。

但如果他们使用向后滑动手势返回,我将无法响应更改。

那么滑动返回手势有回调吗?

目前我只能通过以下方式在我的应用程序中禁用此类页面

interactivePopGestureRecognizer.enabled = NO;
Run Code Online (Sandbox Code Playgroud)

objective-c uinavigationcontroller ios

5
推荐指数
1
解决办法
5584
查看次数

UISearchController 不使用导航控制器

是否可以使用UISearchController而不SearchBar显示在 中Navigation Controller?我基本上希望SearchBar保留在屏幕上并在其下方显示 TableView:

小样

我想做的是:我UITableViewController在故事板上创建了一个并将其链接到自定义NPTableViewController类。然后我这样做了:

    let resultsTable = storyboard!.instantiateViewController(withIdentifier: "LocationSearch") as! NPTableViewController
    searchController = UISearchController(searchResultsController: resultsTable)
    searchController?.searchResultsUpdater = resultsTable

    let searchBar = searchController!.searchBar
    searchBar.sizeToFit()
    searchBar.placeholder = "Search for places"
    searchBar.frame.origin.y = 100.0
    self.view.addSubview(searchBar)
Run Code Online (Sandbox Code Playgroud)

现在,当我运行它时,会searchBar显示 ,但是当我单击它时,背景会变暗,searchBar消失,我的resultsTable也不显示。

iphone uinavigationcontroller uisearchbar swift uisearchcontroller

5
推荐指数
1
解决办法
2742
查看次数

大型导航标题栏默认隐藏

默认情况下显示大型导航栏,但突然更改为较小的标题,可能是在最近的更新中。我遇到了这个问题,UICollectionViewController尽管为了确认,我将以下代码添加到该viewDidLoad方法中。

self.navigationController?.navigationBar.prefersLargeTitles = true
self.navigationItem.largeTitleDisplayMode = .always;
Run Code Online (Sandbox Code Playgroud)

任何线索表示赞赏!:)

uinavigationbar uinavigationcontroller ios swift

5
推荐指数
1
解决办法
2369
查看次数

UIButton 选择器不起作用

我有一个视图作为 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 方法中的目标存在一些问题。可能是什么问题?

button uiview uinavigationcontroller ios swift

5
推荐指数
1
解决办法
1982
查看次数

增加 UINavigationBarLargeTitleView 的高度

我想向导航栏添加一个横幅,但要增加它的高度。我想复制 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)

uinavigationbar uinavigationcontroller ios swift

5
推荐指数
1
解决办法
942
查看次数

如何以编程方式将视图控制器嵌入到导航视图控制器中

我正在尝试将视图控制器嵌入到导航视图控制器中,以便获得导航栏和所有其他内容,例如后退按钮。我想以编程方式完成它。

uiviewcontroller uinavigationcontroller swift

5
推荐指数
1
解决办法
5436
查看次数

将视图控制器推送到另一个视图控制器时如何处理 UIParallaxDimmingView?

我需要将 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 8 上冻结

iOS 应用程序在 PushViewController 上冻结

更新 这是最初的问题如何在弹出的 UIViewController 中删除 UIParallaxDimmingView?

uinavigationcontroller ios swift

5
推荐指数
1
解决办法
1259
查看次数

使用后退按钮从 NavigationController 导航到另一个 NavigationController

在此输入图像描述

你好,所以我有这个storyboard结构,我有一个buttonin ViewController B,我需要它button指向底部NavigationController,其中有ViewController Cas rootViewController,所以当我按 a 时button,ViewContoller B它会带我到C现在,我需要一个后退按钮C来带我回到B

我尝试过查找,但所有参考资料都显示了如何在ViewController不之间进行导航NavigationControllers

storyboard uinavigationcontroller ios swift

5
推荐指数
1
解决办法
3145
查看次数

自定义导航控制器适用于 iOS 13,但不适用于 iOS 12

我创建了一个自定义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 中需要?

initialization uinavigationcontroller ios swift

5
推荐指数
0
解决办法
429
查看次数