What I want to do is to let the popover's top-left equal to the parent view's top-left, I've tried something like this:
override func viewDidLoad() { super.viewDidLoad() let button = UIButton(frame: CGRect(x: 250, y: 250, width: 100, height: 100)) button.backgroundColor = UIColor.red button.addTarget(self, action: #selector(popover), for: .touchUpInside) view.addSubview(button) } @objc func popover() { let contentVC = UIViewController() contentVC.view.frame = CGRect(x: 0, y: 0, width: 300, height: 300) contentVC.view.backgroundColor = UIColor.blue contentVC.modalPresentationStyle = .popover contentVC.preferredContentSize = CGSize(width: 300, height: 300) let popVC = contentVC.popoverPresentationController popVC?.sourceView = view popVC?.sourceRect = CGRect(x: 0, y: 0, width: 300, height: 300) popVC?.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0) popVC?.popoverLayoutMargins = .zero self.present(contentVC, animated: true, completion: nil) }
However the result is like: screenshot But this is what I want: screenshot2
I've also tried to change the modalPresentationStyle as overCurrentContext, but it became fullscreen instead. Is there any way to do that use present viewcontroller? (instead of manually add subview to that position)
https://stackoverflow.com/questions/66988785/how-to-create-a-popover-that-can-reach-the-boundary-of-screen-in-ios April 07, 2021 at 11:01PM
没有评论:
发表评论