【问题标题】:Set height for popover in landscape mode在横向模式下设置弹出框的高度
【发布时间】:2017-04-18 10:41:24
【问题描述】:

我想在横向模式下修改弹出框的高度,但它只能在纵向模式下工作。

我希望它的高度等于screenSize.height * 0.7,但它不适用于下面的代码。

这是我的代码:

if let orientation = UIDevice.current.value(forKey: "orientation") as? Int {
        let diamondViewController = DiamondViewController()
        diamondViewController.mode = .buyDiamondPopup
        diamondViewController.resetBackgroundColor = {
            self.view.backgroundColor = .clear
        }

        let screenSize = UIScreen.main.bounds
        if orientation == 3 { // LandscapeRight
            diamondViewController.preferredContentSize = CGSize(width: screenSize.width * 0.6, height:
                screenSize.height * 0.7)
        } else {
            diamondViewController.preferredContentSize = CGSize(width: screenSize.width - 60, height:
                min(screenSize.height - 180, CGFloat(5 * 70 + 110) ))
        }
        diamondViewController.modalPresentationStyle = .popover
        if let popover = diamondViewController.popoverPresentationController {
            popover.permittedArrowDirections = .init(rawValue: 0)
            popover.sourceView = self.view
            popover.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0)
            popover.delegate = self
            self.view.backgroundColor = UIColor.black.withAlphaComponent(0.5)
            self.present(diamondViewController, animated: true, completion: nil)
        }
    }

...

func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
    return .none
}

【问题讨论】:

    标签: ios swift popover


    【解决方案1】:

    不是这个

     diamondViewController.preferredContentSize = CGSize(width: screenSize.width * 0.6, height: screenSize.height * 0.7)
    

    在下面试试这个

     diamondViewController.view = CGRect(x: diamondViewController.view.frame.origin.x ,y: diamondViewController.view.frame.origin.y ,width: screenSize.width * 0.6, height: screenSize.height * 0.7)
    

    如果没有帮助,请告诉我。

    【讨论】:

      【解决方案2】:

      您是否尝试过使用“因特征而异”工具?它允许您根据设备方向应用不同的约束。它位于情节提要的右下角附近不同约束选项旁边。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-31
        • 1970-01-01
        • 2017-03-19
        • 1970-01-01
        • 1970-01-01
        • 2016-11-29
        相关资源
        最近更新 更多