【发布时间】:2016-07-01 13:41:16
【问题描述】:
我目前正在开发一个应用程序,该应用程序要求用户配置文件在按下用户图片时显示为弹出窗口。我设法使用 UIPopoverPresentationControllerDelegate 获得了这种行为,但我希望你能帮助我在屏幕中间输入这个弹出窗口。
我的代码如下:
func presentProfile(sender: UIButton){
let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("profileVC") as! ProfileViewController
vc.profilePicture = (self.contentIdToImage[content.hostId as! String]?.image)!
vc.modalPresentationStyle = UIModalPresentationStyle.Popover
let height = self.view.bounds.size.height
let width = self.view.bounds.size.width
vc.preferredContentSize = CGSizeMake(width * 0.8, height * 0.8)
if let presentationController = vc.popoverPresentationController {
presentationController.delegate = self
presentationController.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)
presentationController.sourceView = sender
self.presentViewController(vc, animated: true, completion: nil)
}
}
谢谢
编辑:
根据我收到的第一个答案,我开始使用 CGRect,我认为可以使用 UIPopoverPresentationController 的“sourceRect”属性来实现所需的行为,但我还没有弄清楚。
【问题讨论】:
-
我在这里找到了我的问题的解决方案:stackoverflow.com/a/31854391/1270603
标签: ios swift user-interface uipopovercontroller