【问题标题】:Swift programmatic UI UIContextMenuInteraction Auto layout error (groupView) on opening context menuSwift 编程 UI UIContextMenuInteraction 打开上下文菜单时自动布局错误(groupView)
【发布时间】:2020-10-21 00:15:58
【问题描述】:

我有一个带有程序化 UI(无情节提要)的应用。我将上下文菜单添加到我的视图控制器的按钮。打开此菜单时(点击并按住按钮)我在控制台中收到 LayoutConstraints 警告/错误(否则菜单可以正常工作:

(
    "<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。我想我需要在某处为上下文菜单设置它,但我不知道如何或在哪里。

相关代码:

在我的视图控制器中:

        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
    }
}

任何帮助表示赞赏!

【问题讨论】:

    标签: autolayout constraints swift5 uicontextmenuinteraction


    【解决方案1】:

    我在苹果开发者论坛上得到一个回答,说布局警告是一个已知问题,将在iOS14中解决

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-05-05
      • 2015-05-24
      • 1970-01-01
      • 2020-06-05
      • 1970-01-01
      • 2021-07-01
      • 1970-01-01
      相关资源
      最近更新 更多