首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIContextMenuActionProvider在项目上放置不需要的复选标记图标

UIContextMenuActionProvider在项目上放置不需要的复选标记图标
EN

Stack Overflow用户
提问于 2020-02-06 10:55:43
回答 1查看 454关注 0票数 2

问题

我是在实现UIContextMenuInteraction,最后我也无法解释或找到修复的行为。从屏幕截图中可以看到菜单项有检查点的问题。这不是故意的,这些复选标记是自动添加的。理想情况下,我希望使用SF Symbols,但是我添加的任何图像最终都是这个标记。即使我将图像设置为零,它仍然添加了这个奇怪的复选标记。

执行的附加步骤:重新安装SF符号和SF,清理生成,重新启动xCode /模拟器

转载:模拟器iOS 13.3,iPhone 7 iOS 13.3

系统: Catalina 10.15.1,xCode 11.3.1

代码:

代码语言:javascript
复制
import UIKit

class ViewController: UIViewController {

  let sampleView = UIView(frame: CGRect(x: 50, y: 300, width: 300, height: 200))

  override func viewDidLoad() {
    super.viewDidLoad()

    view.addSubview(sampleView)
    sampleView.backgroundColor = .systemIndigo


    let interaction = UIContextMenuInteraction(delegate: self)
    sampleView.addInteraction(interaction)
  }
}

extension ViewController: UIContextMenuInteractionDelegate {

  func contextMenuInteraction(
    _ interaction: UIContextMenuInteraction,
    configurationForMenuAtLocation location: CGPoint
  ) -> UIContextMenuConfiguration? {

    let actionProvider: UIContextMenuActionProvider = { [weak self] _ in

      let like = UIAction(
        title: "Like",
        image: UIImage(systemName: "heart"),
        identifier: nil,
        discoverabilityTitle: nil,
        attributes: [],
        state: .on
      ) { _ in

      }

      let copy = UIAction(
        title: "Copy",
        image: nil,
        identifier: nil,
        discoverabilityTitle: nil,
        attributes: [],
        state: .on
      ) { _ in

      }

      let delete = UIAction(
        title: "Delete",
        image: UIImage(systemName: "trash"),
        identifier: nil,
        discoverabilityTitle: nil,
        attributes: [.destructive],
        state: .on
      ) { _ in

      }

      return UIMenu(
        title: "",
        image: nil,
        identifier: nil,
        options: [],
        children: [
          like, copy, delete
        ]
      )
    }


    let config = UIContextMenuConfiguration(identifier: nil, previewProvider: nil, actionProvider: actionProvider)

    return config

  }

}

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-06 13:16:47

您需要将UIAction.state.on更改为.off,以消除复选标记。

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

https://stackoverflow.com/questions/60093347

复制
相关文章

相似问题

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