首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >打开上下文菜单上的快速编程UI UIContextMenuInteraction自动布局错误(groupView)

打开上下文菜单上的快速编程UI UIContextMenuInteraction自动布局错误(groupView)
EN

Stack Overflow用户
提问于 2020-06-30 16:13:28
回答 1查看 232关注 0票数 2

我有一个程序界面的应用程序(没有故事板)。我将上下文菜单添加到视图控制器的一个按钮中。在打开这个菜单(点击并按住按钮)时,我在控制台中得到一个LayoutConstraints警告/错误(否则菜单工作得很好:

代码语言:javascript
复制
(
    "<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。我想我需要将它设置为上下文菜单的某个位置,但我不知道如何设置,也不知道在哪里。

相关守则:

在我的视图控制器中:

代码语言:javascript
复制
        let interaction = UIContextMenuInteraction(delegate: self)
        annotationTypeButton.addInteraction(interaction)

代表分机:

代码语言:javascript
复制
//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
    }
}

任何帮助都很感激!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-03 11:31:50

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

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62661755

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档