Swift 是否更改上下文菜单中UIImage的弹出窗口大小?
假设你有一个图像的上下文菜单,当长按时会弹出。如何使弹出窗口变大,但保持相同的尺寸Swift 是否更改上下文菜单中UIImage的弹出窗口大小?,swift,firebase,uiimageview,contextmenu,uicontextmenuinteraction,Swift,Firebase,Uiimageview,Contextmenu,Uicontextmenuinteraction,假设你有一个图像的上下文菜单,当长按时会弹出。如何使弹出窗口变大,但保持相同的尺寸 您可以向上下文菜单提供自己的预览提供程序。只需创建一个带有图像视图的自定义视图控制器,以便以所需大小预览图像: import UIKit class ImagePreviewController: UIViewController { private let imageView = UIImageView() init(image: UIImage) { super.init
您可以向上下文菜单提供自己的预览提供程序。只需创建一个带有图像视图的自定义视图控制器,以便以所需大小预览图像:
import UIKit
class ImagePreviewController: UIViewController {
private let imageView = UIImageView()
init(image: UIImage) {
super.init(nibName: nil, bundle: nil)
preferredContentSize = image.size
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
imageView.image = image
view = imageView
}
required init?(coder: NSCoder) {
super.init(coder: coder)
}
}
然后只需将自定义预览提供程序实现添加到
UIContextMenuConfiguration
初始值设定项:
func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {
UIContextMenuConfiguration(identifier: nil) {
ImagePreviewController(image: self.immy.image!)
} actionProvider: { _ in
let share = UIAction(title: "Share", image: UIImage(systemName: "square.and.arrow.up")) { _ in
// share code
}
return UIMenu(title: "Profile Picture Menu", children: [share])
}
}
编辑/更新: 不采取任何行动
func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {
UIContextMenuConfiguration(identifier: nil, previewProvider: {
ImagePreviewController(image: self.immy.image!)
})
}
评论不用于扩展讨论;这段对话已经结束。嗨,兄弟,我正在使用上下文菜单并添加一些反应按钮,但无法单击,你是否遇到过这个问题?
func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {
UIContextMenuConfiguration(identifier: nil) {
ImagePreviewController(image: self.immy.image!)
} actionProvider: { _ in
let share = UIAction(title: "Share", image: UIImage(systemName: "square.and.arrow.up")) { _ in
// share code
}
return UIMenu(title: "Profile Picture Menu", children: [share])
}
}
func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {
UIContextMenuConfiguration(identifier: nil, previewProvider: {
ImagePreviewController(image: self.immy.image!)
})
}