Ios 如何使UIView位于UIAbbarController中所有选项卡的顶部

Ios 如何使UIView位于UIAbbarController中所有选项卡的顶部,ios,swift,inheritance,uiview,uitabbarcontroller,Ios,Swift,Inheritance,Uiview,Uitabbarcontroller,使uiview位于uitabbar控制器所有选项卡的顶部。 我计划制作一个名为“uiView.swift”的baseviewcontroller。在“uiView.swift”中,我添加了我的uiView。之后,我想从uiView.swift继承每个选项卡ViewController(比如“restreent.swift”)。因此,在UIAbbarController的每个选项卡中,您将看到“uiView.swift”视图Resured.uiView.swift连接到故事板中的ViewContr

使uiview位于uitabbar控制器所有选项卡的顶部。 我计划制作一个名为“uiView.swift”的baseviewcontroller。在“uiView.swift”中,我添加了我的uiView。之后,我想从uiView.swift继承每个选项卡ViewController(比如“restreent.swift”)。因此,在UIAbbarController的每个选项卡中,您将看到“uiView.swift”视图Resured.uiView.swift连接到故事板中的ViewController,故事板中有一个按钮,该按钮在单击按钮时显示视图。这是我的“uiView.swift”

如何在tabbar控制器的每个选项卡(即“restreent.swif”)中重用“uiView.swift”中的视图


uiView.swift的类型为UIViewController,Restreent.swif的类型为UICollectionViewController。您可以将应用程序的入口点从uiView.swift更改为登录视图控制器(Viewcontroller.swift)运行应用程序。如何通过继承重用uiView.swift中的视图?您可以从此链接下载项目。

您不应在任何视图上添加菜单视图。您可以直接从AppDelegate将其添加到窗口中,而不是执行此操作。
在窗口中添加视图将使其位于当前可见的所有视图之上。

您是否在tabBarController上弹出窗口,并且希望该窗口位于当前显示的所有视图之上。对吗?单击按钮时在tabbar控制器上弹出?单击按钮时可以突出显示当前正在执行的操作吗?单击uiView.swift按钮时,单击仅显示视图。我希望通过继承tabbar控制器所有选项卡上的内容来复制此显示视图。您可以将应用程序的入口点从uiView.swift更改为登录视图控制器(Viewcontroller.swift)运行应用程序。我想在我的所有选项卡栏控制器上都有uiview。我认为在我的所有选项卡栏控制器上都有uiview的方式是通过继承uiview.swift到选项卡栏控制器的所有选项卡的视图。我如何完成这项任务?为什么你想在每个视图控制器上显示东西?因为你们可以在上面显示一个。我只想弹出按钮,点击tabBarController的每个选项卡
class uiView: UIViewController {
var menuView: UIView?

    override func viewDidLoad() {
        super.viewDidLoad()
        menuView = UIView(frame: CGRect(x: 0, y: -200, width: 420, height: 200))
        menuView?.backgroundColor = UIColor.green
        view.addSubview(menuView!)
    }
    @objc func MyBag(){

    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    @IBAction func collectionmenuone(_ sender: Any) {
       menuView=UIView(frame: CGRect(x: 0, y: 0, width: 420, height: 200))
        menuView?.backgroundColor=UIColor.lightGray
        self.view.addSubview(menuView!)

        var btnbag = UIButton(type: .roundedRect)
        btnbag.addTarget(self, action: #selector(self.MyBag), for: .touchUpInside)
        btnbag.frame = CGRect(x: 104, y:130 , width: 150, height: 60)
        btnbag.setTitle("Done", for: .normal)
        btnbag.backgroundColor=UIColor.green
        menuView?.addSubview(btnbag)

    }


}
class resturent:UICollectionViewController,UICollectionViewDelegateFlowLayout {

    override func viewDidLoad() {
        super.viewDidLoad()
        navigationItem.title="Seafood"
        collectionView?.backgroundColor=UIColor.white
        // view.backgroundColor=UIColor.redColor
        collectionView?.register(VideoCell.self, forCellWithReuseIdentifier: "cellid")
    }
    override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 5
    }
    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell=collectionView.dequeueReusableCell(withReuseIdentifier: "cellid", for: indexPath)
        // cell.backgroundColor=UIColor.red
        return cell
    }
    /* override func collectionView(collectionView: UICollectionView, cellForItemAtIndexpath indexPath: NSIndexPath) -> UICollectionViewCell {
     let cell=collectionView.dequeueReusableCell(withReuseIdentifier: "cellId", for: indexPath as IndexPath)

     return cell
     }*/
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
        return 0
    }
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        let height=(view.frame.width - 16 - 16) * 9/16
        return  CGSize(width: view.frame.width, height: height + 16 + 68)
    }
}
class VideoCell:UICollectionViewCell{
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupView()
    }
    let thumbnailImageView:UIImageView = {
        let imageView=UIImageView()
        imageView.backgroundColor=UIColor.blue
        imageView.image=UIImage(named: "food24")
        imageView.contentMode = .scaleAspectFill
        imageView.clipsToBounds=true
        return imageView
    }()
    let userProfileImageView:UIImageView={
        let imageView=UIImageView()
        //imageView.backgroundColor=UIColor.green
        return imageView
    }()
    let separatorView:UIView = {
        let view = UIView ()
        view.backgroundColor=UIColor(red: 230/255, green: 230/255, blue: 230/255, alpha: 1)
        return view
    }()
    let titleLabel:UILabel={
        let label = UILabel()
        label.translatesAutoresizingMaskIntoConstraints=false
        label.text="Resturant name here"
        return label
    }()
    let subtitleTextView:UITextView = {
        let textView=UITextView()
        textView.translatesAutoresizingMaskIntoConstraints=false
        textView.textContainerInset=UIEdgeInsetsMake(0, -4, 0, 0)
        textView.textColor=UIColor.lightGray
        textView.text = "SeaFood"
        return textView
    }()
    func setupView()  {
        //backgroundColor=UIColor.blue
        addSubview(thumbnailImageView)
        addSubview(separatorView)
        addSubview(userProfileImageView)
        addSubview(titleLabel)
        addSubview(subtitleTextView)
        addConstraintsWithFormat(format: "H:|-16-[v0]-16-|", view: thumbnailImageView)
        addConstraintsWithFormat(format: "H:|-16-[v0(44)]", view: userProfileImageView)
        //vertial constratints
        addConstraintsWithFormat(format: "V:|-16-[v0]-8-[v1(44)]-16-[v2(1)]|", view: thumbnailImageView,userProfileImageView,separatorView)
        addConstraintsWithFormat(format: "H:|[v0]|", view: separatorView)
        //top constraints
        addConstraint(NSLayoutConstraint(item: titleLabel, attribute: .top, relatedBy: .equal, toItem:thumbnailImageView , attribute: .bottom, multiplier: 1, constant: 8))
        //left constaints
        addConstraint(NSLayoutConstraint(item: titleLabel, attribute: .left, relatedBy: .equal, toItem: userProfileImageView, attribute: .right, multiplier: 1, constant: 8))
        //right constraint
        addConstraint(NSLayoutConstraint(item: titleLabel, attribute: .right, relatedBy: .equal, toItem: thumbnailImageView, attribute: .right, multiplier: 8, constant: 0))
        //height constraint
        addConstraint(NSLayoutConstraint(item: titleLabel, attribute: .height, relatedBy: .equal, toItem: self, attribute: .height, multiplier: 0, constant: 20))

        //top constraints
        addConstraint(NSLayoutConstraint(item: subtitleTextView, attribute: .top, relatedBy: .equal, toItem:titleLabel , attribute: .bottom, multiplier: 1, constant: 4))
        //left constaints
        addConstraint(NSLayoutConstraint(item: subtitleTextView, attribute: .left, relatedBy: .equal, toItem: userProfileImageView, attribute: .right, multiplier: 1, constant: 8))
        //right constraint
        addConstraint(NSLayoutConstraint(item: subtitleTextView, attribute: .right, relatedBy: .equal, toItem: thumbnailImageView, attribute: .right, multiplier: 8, constant: 0))
        //height constraint
        addConstraint(NSLayoutConstraint(item: subtitleTextView, attribute: .height, relatedBy: .equal, toItem: self, attribute: .height, multiplier: 0, constant: 20))


        // addConstraintsWithFormat(format: "V:[v0(20)]", view: titleLabel)
        //  addConstraintsWithFormat(format: "H:|[v0]|", view: titleLabel)

    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
extension UIView{
    func addConstraintsWithFormat(format:String,view:UIView...){
        var viewDictionary=[String:UIView]()
        for (index,view) in view.enumerated(){
            let key="v\(index)"
            view.translatesAutoresizingMaskIntoConstraints=false
            viewDictionary[key]=view
        }
        NSLayoutConstraint.activate(NSLayoutConstraint.constraints(withVisualFormat: format , options: NSLayoutFormatOptions(), metrics: nil, views: viewDictionary))
    }

}