可以创建从View Controller角落出现的UITableView

时间:2018-05-17 19:20:42

标签: swift xcode uitableview uiviewcontroller uiscrollview

我想在Todoist应用程序中找到一个表视图后进行建模(见下文),是否可以在没有其他框架的情况下执行此操作?如果是这样,我将如何做到这一点?enter image description here

1 个答案:

答案 0 :(得分:3)

您可以使用UITableView创建一个视图控制器,并将其显示为UIPopoverPresentationController

let vc = UIViewController()

vc.modalPresentationStyle = .popover

vc.preferredContentSize = CGSize(width: 200, height: 200)

let popUp = vc.popoverPresentationController

popUp?.permittedArrowDirections = .up

popUp?.delegate = self

popUp?.sourceView = sender as! UIView  // here set the frame of the button that the arrow points to when popup is shown

present(vc, animated: true, completion: nil)

//

在你提供弹出窗口的vc中,它实现了委托UIPopoverPresentationControllerDelegate并编写了这个方法

func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
    return .none
}