Swift 程序化 UI UIContextMenuInteraction 打开上下文菜单时出现自动布局错误 (groupView)

Swift programmatic UI UIContextMenuInteraction Auto layout error (groupView) on opening context menu

我有一个程序化的应用程序 UI(没有故事板)。我将上下文菜单添加到 viewcontroller 的按钮。打开此菜单(点击并按住按钮)后,我在控制台中得到 LayoutConstraints warning/error(否则菜单工作正常:

(
    "<NSAutoresizingMaskLayoutConstraint:0x600001c9ed50 h=--& v=--& UIInterfaceActionGroupView:0x7f9d4478ceb0.height == 0   (active)>",
    "<NSLayoutConstraint:0x600001cd7c50 groupView.actionsSequence....height >= 66   (active, names: groupView.actionsSequence...:0x7f9d4610ee00 )>",
    "<NSLayoutConstraint:0x600001cb3de0 UIInterfaceActionGroupView:0x7f9d4478ceb0.top == _UIContentConstraintsLayoutGuide:0x7f9d4478bba0''.top   (active)>",
    "<NSLayoutConstraint:0x600001cb3e80 V:[_UIContentConstraintsLayoutGuide:0x7f9d4478bba0'']-(0)-|   (active, names: '|':UIInterfaceActionGroupView:0x7f9d4478ceb0 )>",
    "<NSLayoutConstraint:0x600001cad090 groupView.actionsSequence....top == _UIContentConstraintsLayoutGuide:0x7f9d4478bba0''.top   (active, names: groupView.actionsSequence...:0x7f9d4610ee00 )>",
    "<NSLayoutConstraint:0x600001cad130 groupView.actionsSequence....bottom == _UIContentConstraintsLayoutGuide:0x7f9d4478bba0''.bottom   (active, names: groupView.actionsSequence...:0x7f9d4610ee00 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600001cd7c50 groupView.actionsSequence....height >= 66   (active, names: groupView.actionsSequence...:0x7f9d4610ee00 )>

这个groupView不是我的视图!我在所有自定义控件(标签、字段等)上设置了 translatesAutoresizingMaskIntoConstraints = false。我想我需要将其设置为某处的上下文菜单,但我不知道如何或在哪里。

相关代码:

在我的 viewcontroller:

        let interaction = UIContextMenuInteraction(delegate: self)
        annotationTypeButton.addInteraction(interaction)

代表分机:

//MARK: - UIContextMenuInteractionDelegate
extension AnnotationDetailsViewController: UIContextMenuInteractionDelegate {
    func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {
        return UIContextMenuConfiguration(identifier: "annotationTypeMenu" as NSCopying, previewProvider: nil) { _ in
            let children: [UIMenuElement] = self.makeAnnotationTypeActions()
            return UIMenu(title: "", children: children)
        }
    }
    
    func makeAnnotationTypeActions() -> [UIAction] {
        var actions = [UIAction]()
        for type in AnnotationType.allCases {
            actions.append( UIAction(title: type.rawValue, image: type.image, identifier: nil, attributes: []) { _ in
                let annotationType = AnnotationType(rawValue: type.rawValue) ?? AnnotationType.tips
                self.annotation.type = annotationType
                self.configureAnnotationTypeButton(with: annotationType)
            })
        }
        return actions
    }
}

感谢任何帮助!

我在 Apple 开发者论坛上得到一个答案,说 布局警告是一个已知问题,将在 iOS14!

中解决

https://developer.apple.com/forums/thread/652622?login=true&page=1#618265022