Swift UITableViewCell的button处展示p

2021-01-14  本文已影响0人  喵喵粉
  1. senderUITableViewCell上的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) { }
}
  1. 实现代理UIPopoverPresentationControllerDelegate
extension xxxVC: UIPopoverPresentationControllerDelegate {
    
    ///此处为不适配(如果选择其他,上面设置的大小就毫无意义了)
    func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
        return .none
    }
}
  1. 效果
image.png
上一篇 下一篇

猜你喜欢

热点阅读