问题描述
- 如果它是默认属性,那么如何使用它? (是否在
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)