gpt4 book ai didi

iOS 13.0 UIMenu 和 UIContextMenuConfiguration 的 UIAction

转载 作者:搜寻专家 更新时间:2023-10-31 19:26:38 25 4
gpt4 key购买 nike

我正在尝试使用 iOS 13.0 Beta 中引入的新 API。我已经下载了 Xcode 11.0 Beta 3 以便能够访问这些 API。

我在网上找到的一些代码执行如下操作:

extension SingleViewController: UIContextMenuInteractionDelegate {
func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {
let configuration = UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { actions -> UIMenu<UIAction>? in
// Creating Save button
let save = UIAction(__title: "Save", image: UIImage(systemName: "tray.and.arrow.down.fill"), options: []) { action in
// Just showing some alert
self.showAlert(title: action.title)
}

// Creating Rotate button
let rotate = UIAction(__title: "Rotate", image: UIImage(systemName: "arrow.counterclockwise"), options: []) { action in
self.showAlert(title: action.title)
}
// Creating Delete button
let delete = UIAction(__title: "Delete", image: UIImage(systemName: "trash.fill"), options: .destructive) { action in
self.showAlert(title: action.title)
}
// Creating Edit, which will open Submenu
let edit = UIMenu<UIAction>.create(title: "Edit...", children: [rotate, delete])

// Creating main context menu
return UIMenu<UIAction>.create(title: "Menu", children: [save, edit])
}
return configuration
}
}

这看起来不错,但甚至无法在我的 Xcode 中编译。我得到的错误是:

Cannot specialize non-generic type 'UIMenu' Replace '<UIAction>' with ''

关于创建配置常量。

Type of expression is ambiguous without more context

关于创建保存操作。

并结合其他类似的错误。

我还应该提一下,我什至没有这种格式的构造函数:

UIAction(__title: "String", image: UIImage, options: Array)
UIMenu.create(...)

为什么 Xcode-11 beta 3.0 中缺少这些?

最佳答案

嗯,它变了。这是测试版!我希望它再次改变,但现在,在 beta 3 中,UIAction 的初始化器是

init(__title title: String, image: UIImage?, identifier: UIAction.Identifier?, 
handler: @escaping UIActionHandler)

UIMenu 不是通用的,它的初始化器是

init(__title title: String, image: UIImage?, identifier: UIMenu.Identifier?, 
options: UIMenu.Options = [], children: [UIMenuElement])

所以这里重写了在 beta 3 下编译的代码:

func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {
let configuration = UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { actions -> UIMenu? in
let save = UIAction(__title: "Save", image: UIImage(systemName: "tray.and.arrow.down.fill"), identifier: nil) { action in
// whatever
}
let rotate = UIAction(__title: "Rotate", image: UIImage(systemName: "arrow.counterclockwise"), identifier: nil) { action in
// whatever
}
let delete = UIAction(__title: "Delete", image: UIImage(systemName: "trash.fill"), identifier: nil) { action in
// whatever
}
let edit = UIMenu(__title: "Edit", image: nil, identifier: nil, children:[rotate,delete])
return UIMenu(__title: "Menu", image: nil, identifier: nil, children:[save, edit])
}
return configuration
}

关于iOS 13.0 UIMenu 和 UIContextMenuConfiguration 的 UIAction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56960374/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com