Dav*_*eck 5 contextmenu ios swift ios13
我的应用程序支持 iOS 13 暗模式,并为用户提供匹配系统外观或强制应用程序始终使用暗模式或亮模式的选项,而不管系统设置如何。
该应用程序还允许在用户按下 时显示上下文菜单UILabel。但是,当使用UIContextMenuInteractionDelegate方法呈现上下文菜单时,我找不到任何方法来覆盖菜单的深色/浅色外观,也找不到UITargetedPreview在上下文菜单出现和消失时动画的视图外观。
例如,如果 iOS 外观设置为浅色模式并且用户在应用程序中选择强制深色模式的选项,则上下文菜单显示为浅色。我想覆盖该行为,使它们看起来很暗 - 有什么方法可以实现这一目标吗?我似乎找不到overrideUserInterfaceStyle与上下文菜单相关的属性。
我使用的代码如下供参考。
// Setup code
if #available(iOS 13.0, *) {
self.textLabel.addInteraction(UIContextMenuInteraction(delegate: self))
}
// UIContextMenuInteractionDelegate
@available(iOS 13.0, *)
func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {
let text = self.text
return UIContextMenuConfiguration(identifier: nil, previewProvider: { return TextViewController(text: text) }) { [weak self] _ in
return self?.contextMenu(for: text)
}
}
@available(iOS 13.0, *)
private func contextMenu(for text: String) -> UIMenu {
let copy = UIAction(title: "Copy", image: UIImage(systemName: "doc.on.doc")) { _ in
// Perform 'text' copy
}
let share = UIAction(title: "Share", image: UIImage(systemName: "square.and.arrow.up")) { _ in
// Present system share sheet
}
return UIMenu(title: "", children: [copy, share])
}
Run Code Online (Sandbox Code Playgroud)
我使用以下命令强制显示上下文菜单的视图控制器的外观:
overrideUserInterfaceStyle = .dark // or .light
Run Code Online (Sandbox Code Playgroud)
因此,我面临的问题不在于我的UIViewController.
AppDelegate在 iOS 13 及更高版本中添加以下行SceneDelegate。
self.window?.overrideUserInterfaceStyle = .light / .dark
Run Code Online (Sandbox Code Playgroud)
UIViewController:添加以下内容ViewDidLoad:
self.overrideUserInterfaceStyle = .light / .dark
Run Code Online (Sandbox Code Playgroud)
UIView:view.overrideUserInterfaceStyle = .light / .dark
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1554 次 |
| 最近记录: |