如何在 Swift 5 中从 NavigationBar 选择 UIBarButtonItem 时显示带有 opening/closing 效果的弹出窗口?

How to show popUp with opening/closing effects when selecting UIBarButtonItem from NavigationBar in Swift 5?

Is this any Default Property in updated iOS14 or is it made in SwiftUI or is it a custom UIView?

谢谢

这个 Dropdown

有一个非常好的 cocoa 播客

它的工作原理也很简单

正在创建下拉菜单

let dropDown = DropDown()
// The view to which the drop down will appear on
    dropDown.anchorView = view // UIView or UIBarButtonItem
// The list of items to display. Can be changed dynamically
    dropDown.dataSource = ["Car", "Motorcycle", "Truck"]

可选操作属性

// Action triggered on selection
dropDown.selectionAction = { [unowned self] (index: Int, item: String) in
  print("Selected item: \(item) at index: \(index)")
}

// Will set a custom width instead of the anchor view width
dropDownLeft.width = 200

显示操作是

dropDown.show()
dropDown.hide()

您还可以做一些非常高级的事情,例如自定义单元格、显示方向等,请查看 Documentation

iOS14(UIKit 和 swiftUI)中有一项称为下拉菜单或上下文菜单的新功能。现在可以将菜单添加到 UIButtons 和 UIBarbuttonItems。

let tbMenu = UIMenu(title: "", children: /* UIActions */)
UIBarButtonItem(image: UIImage(systemName: "list.number"), menu: buttonMenu)

Pull-down menus Context menus(对于 TableView)