Swift UITableViewCell的button处展示p
2021-01-14 本文已影响0人
喵喵粉
-
sender
是UITableViewCell
上的UIButton
SelectTagCollectionVC
只有UICollectionView
fileprivate func showTags(sender: UIButton) {
let selectTagVC = SelectTagCollectionVC()
selectTagVC.preferredContentSize = CGSize(width: kScreenW, height: kScreenW/2)
selectTagVC.modalPresentationStyle = .popover
let popPC = selectTagVC.popoverPresentationController
popPC?.delegate = self
popPC?.sourceView = sender
popPC?.backgroundColor = .white
present(selectTagVC, animated: true) { }
}
- 实现代理
UIPopoverPresentationControllerDelegate
extension xxxVC: UIPopoverPresentationControllerDelegate {
///此处为不适配(如果选择其他,上面设置的大小就毫无意义了)
func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
return .none
}
}
- 效果