从Swift 5的NavigationBar中选择UIBarButtonItem时,如何显示带有打开/关闭效果的弹出窗口?

问题描述

enter image description here

这是更新的iOS14中的任何属性,还是在SwiftUI中创建,还是自定义UIView

  • 如果它是属性,那么如何使用它? (是否在 Apple Documentation
  • 如果它位于SwiftUI中,如何在Swift5中使用此属性
  • 如果它是自定义UIView,那么我该如何 用打开和关闭动画效果创建一个(如果有) 运行iOS 14+的iPhone,则当您看到动画效果时 它打开或关闭,就像是缩放动画(我猜是)一样。

谢谢

解决方法

这个Dropdown

有一个很好的可可豆荚

它的工作也很简单

创建下拉列表

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(用于TableViews)