简体   繁体   English

如何将 UIView 底部锚点向右移动到底部导航栏?

[英]How do I move my UIView bottom anchor right about my bottom navigation bar?

I have a controller that will display UIView that displays a text field at the bottom, but I already have a navigation bar down there so whenever I run the simulator, the navigation bar covers it.我有一个 controller,它将显示 UIView,在底部显示一个文本字段,但我已经有一个导航栏,所以每当我运行模拟器时,导航栏都会覆盖它。 How would I move that UIView right above my navigation bar?如何将 UIView 移动到导航栏上方? I was messing around with the anchors but I am still having trouble.我在搞乱锚,但我仍然遇到麻烦。 I was messing around with the containerView.bottomAnchor.我在搞乱 containerView.bottomAnchor。

import UIKit

class ChatLogController: UICollectionViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        navigationItem.title = "Chat Log Controller"

        collectionView?.backgroundColor = UIColor.white

        setUpInputComponents()

    }

    func setUpInputComponents() {
        let containerView = UIView()
        containerView.backgroundColor = UIColor.red
        containerView.translatesAutoresizingMaskIntoConstraints = false

        view.addSubview(containerView)

        containerView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
        containerView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
        containerView.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
        containerView.widthAnchor.constraint(equalToConstant: 50).isActive = true



        let sendButton = UIButton(type: .system)
        sendButton.setTitle("Send", for: .normal)
        sendButton.translatesAutoresizingMaskIntoConstraints = false
        containerView.addSubview(sendButton)
        sendButton.rightAnchor.constraint(equalTo: containerView.rightAnchor).isActive = true
        sendButton.centerYAnchor.constraint(equalTo: containerView.centerYAnchor).isActive = true
        sendButton.widthAnchor.constraint(equalToConstant: 80).isActive = true
        sendButton.heightAnchor.constraint(equalTo: containerView.heightAnchor).isActive = true

        let inputTextField = UITextField()
        inputTextField.placeholder = "Enter message..."
        inputTextField.translatesAutoresizingMaskIntoConstraints = false
        containerView.addSubview(inputTextField)

        inputTextField.leftAnchor.constraint(equalTo: containerView.leftAnchor, constant: 8).isActive = true
        inputTextField.centerYAnchor.constraint(equalTo: containerView.centerYAnchor).isActive = true
        inputTextField.rightAnchor.constraint(equalTo: sendButton.leftAnchor).isActive = true
        inputTextField.heightAnchor.constraint(equalTo: containerView.heightAnchor).isActive = true


        let seperatorLineView = UIView()
        seperatorLineView.backgroundColor = UIColor.black
        seperatorLineView.translatesAutoresizingMaskIntoConstraints = false
        containerView.addSubview(seperatorLineView)

        seperatorLineView.leftAnchor.constraint(equalTo: containerView.leftAnchor).isActive = true
        seperatorLineView.topAnchor.constraint(equalTo: containerView.topAnchor).isActive = true
        seperatorLineView.widthAnchor.constraint(equalTo: containerView.widthAnchor).isActive = true
        seperatorLineView.heightAnchor.constraint(equalToConstant: 1).isActive = true


    }
}

https://imgur.com/a/Cm2jlsy https://imgur.com/a/Cm2jlsy

Set tabBarController.tabBar.translucent to true to make your tabbar opaque.tabBarController.tabBar.translucent设置为true以使您的标签栏不透明。

tabBarController.tabBar.opaque = true
tabBarController.tabBar.translucent = true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将UIView移动到“底部”以便显示下一个UIView? - How do I move the UIView to the “bottom” so that the next UIView displays? 如何在UIVIew的底部添加阴影 - How do I add a shadow to the bottom of a UIVIew 当我尝试在 Flutter 中实现底部导航栏时,为什么我的应用程序崩溃了? - Why is my app crashing when I try to implement my bottom navigation bar in Flutter? 如何在不使用IB的代码中将自定义导航栏保持在屏幕底部 - How do I keep my custom nav bar at bottom of screen in code without IB 我需要在我的 iOS 应用程序中添加一个标签栏,以便用户可以左右滚动它(在底部)。 任何人都可以建议如何去做吗? - I need to add a tab bar in my iOS App so that user can scroll it left-right(in the bottom). Can anyone suggest how to to it? 如何让我的 UITableViewController 页脚贴在底部? - How do I make my UITableViewController footer stick to the bottom? 我如何定位footerView,使其位于UITableView的底部? - How do i position my footerView so that it is on the bottom of the UITableView? 如何让我的iAd横幅出现在屏幕底部? - How do I make my iAd banner appear at bottom of screen? 是否可以将 UIView 的顶部固定到导航栏的底部? - Is it possible to pin a UIView's top to the bottom of the navigation bar? 如何在xcode中移动UIView? - How can I move my UIView in xcode?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM