ios - 以 UITextField 作为 subview 的 UINavigation

标签 ios objective-c iphone

我想制作如下的 UI,

enter image description here

我试着像这样增加 UINavigationController 的高度

[self.navigationController.navigationBar setFrame:CGRectMake(0, 0, 320, 110)];

但导航标题和 BarButtonItem 出现在下方。 我无法添加隐藏导航,因为我正在使用使用 Left BarButtonItem 的第三方侧边菜单。

我可以很好地保持导航的原样,在下面我添加了 uiview 作为 subview ,其背景颜色与导航的背景颜色相同,但两者之间出现细线...:(

最佳答案

您不能增加 UINavigationBar 的高度。在 UINavigationBar 下方添加一个包含这些元素的 UIView。

UINavigationBar 下方会多出一行。您可以删除该行。引用How to hide iOS7 UINavigationBar 1px bottom line

或者使用这段代码(我刚刚从那个链接中快速复制了它,将它转换为 Objective-C)

import UIKit

class ViewController: UIViewController {

    private var shadowImageView: UIImageView?

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        if shadowImageView == nil {
            shadowImageView = findShadowImage(under: navigationController!.navigationBar)
        }
        shadowImageView?.isHidden = true
    }

    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)

        shadowImageView?.isHidden = false
    }

    private func findShadowImage(under view: UIView) -> UIImageView? {
        if view is UIImageView && view.bounds.size.height <= 1 {
            return (view as! UIImageView)
        }

        for subview in view.subviews {
            if let imageView = findShadowImage(under: subview) {
                return imageView
            }
        }
        return nil
    }
}

这是结果

enter image description here

关于ios - 以 UITextField 作为 subview 的 UINavigation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41277211/

相关文章:

ios - 为什么苹果推荐使用 dispatch_once 来实现 ARC 下的单例模式?

android - 使用 React Native 时,我有哪些存储数据的选项? (iOS 和安卓)

ios - Xcode 10 - iPhone X 黑条

ios - 此处 Maps iOS SDK 问题(Swift3、Xcode 8)的 currentPosition 为零

ios - Cordova batterystatus - 如何立即升级?

iphone - 刷新 iPhone 上的 TextView 滚动位置

iphone - 如何在 UIImageView 上制作可点击的 UIButton?

ios - 无法设置 MPMusicPlayerController.shuffleMode

ios - TTTAttributedLabel 检测多链接

iphone - 如何获取两个单词之间的 NSString?