如何将包含动态高度内容的popupview居中?

时间:2017-04-25 09:41:44

标签: ios iphone swift swift3 uikit

我现在根据这个YouTube视频“https://www.youtube.com/watch?v=FgCIRMz_3dE”实现我的iOS应用程序的弹出对话框。但问题是我无法将弹出视图设置为固定高度,因为有动态高度标签在我的弹出视图中,这是在我的弹出视图控制器内。任何人都可以告诉我如何解决这个问题?感谢您的关注。

This is my popup view controller structure.The opacity of underlying background is reduced to see the content of the parent view.

这是我从父视图控制器打开弹出视图控制器的代码。

let PopUpVC = UIStoryboard(name:"Main", bundle:nil).instantiateViewController(withIdentifier: "FeedPopUpViewController") as! FeedPopUpViewController

        self.addChildViewController(PopUpVC)
        PopUpVC.view.frame = self.view.frame
        self.view.addSubview(PopUpVC.view)
        PopUpVC.didMove(toParentViewController: self)

这是我的FeedPopUpView控制器代码

import UIKit

class FeedPopUpViewController: UIViewController {
    @IBOutlet weak var action_Label: UILabel!

    @IBAction func dismiss(_ sender: Any) {
        print("pop up is dismissed")
        self.view.removeFromSuperview()
    }
    override func viewDidLoad() {
        self.showAnimate()
        super.viewDidLoad()
        print("pop up is created")
    }

    override func viewWillAppear(_ animated: Bool) {
        print("pop up is appeared")
    }

    func showAnimate(){

    }
}

1 个答案:

答案 0 :(得分:0)

PopUpVC.view.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive = true

这应该做的工作:)