我想总是ViewController在所有设备和所有方向上提供一个popover.我试图通过采用UIPopoverPresentationControllerDelegate和设置sourceView和来完成这个sourceRect.
这适用于所有设备和方向,除了横向的iPhone 6 Plus.在这种情况下,视图控制器在表单中从屏幕底部向上滑动.如何防止它始终出现在弹出框中?
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let popoverPresentationController = segue.destinationViewController.popoverPresentationController
popoverPresentationController?.delegate = self
popoverPresentationController?.sourceView = self.titleLabel!.superview
popoverPresentationController?.sourceRect = self.titleLabel!.frame }
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
return UIModalPresentationStyle.None }
Run Code Online (Sandbox Code Playgroud)
所有设备均在iOS 8.2或更高版本下
我正在尝试UIPopoverPresentationController在我的iPhone应用程序中实现新功能(使用Objective C).我想要的是一个简单的popover,其中包含一个从启动按钮发出的tableview.
- 编辑 -
这是我的修订代码,改编自文档中的研究,SO,以及下面评论中的输入:
- (IBAction)selectCategoryBtn:(UIButton *)sender
{
[self performSegueWithIdentifier:@"CatSelectSegue" sender:self.selCatButton];
}
-(void) prepareForSegue:(UIStoryboardSegue *) segue Sender:(id) sender
{
if (sender == self.selCatButton)
{
if ([segue.identifier isEqualToString:@"CatSelectSegue"])
{
UIPopoverPresentationController *controller = segue.destinationViewController;
controller.delegate = self;
controller.sourceView = self.selCatButton;
controller.sourceRect = self.selCatButton.frame;
}
}
}
-(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
{
return UIModalPresentationNone;
Run Code Online (Sandbox Code Playgroud)
这是我的故事板连接:

然而,这只是以模态方式呈现一个桌面视图,从底部上升并消耗整个屏幕.
我用谷歌搜索了,看起来都是如此,但看起来我并不是唯一一个被我希望解决iPhone烦恼问题所迷惑的人.
任何人都可以看到我的代码中的故障或指导我一个明确的教程?我看过了,但也许API是如此新的没有人能够掌握它.
谢谢!
第二次编辑:
以下是上述代码的结果.我减少了视图控制器中的tableview的大小,我希望将其作为弹出窗口呈现.我把背景涂成灰色,只是为了澄清出现的是什么,而不是弹出窗口.

我正在创建和呈现ActionSheet如下:
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .ActionSheet)
alertController.modalPresentationStyle = .Popover
// Add some buttons
alertController.popoverPresentationController?.delegate = self
alertController.popoverPresentationController?.barButtonItem = someBarButton
self.presentViewController(alertController, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
这工作正常在iPad上,不过alertController.popoverPresentationController是nil在iPhone上.
我已经成功地使用自适应segue样式在iPhone上使用自适应segue样式呈现弹出窗口并实现adaptivePresentationStyleForPresentationController委托方法以返回正确的UIModalPresentationStyle但是我已经卡住了如何在代码中执行它,UIAlertController因为它popoverPresentationController在iPhone 上没有
我设置了UIPopoverPresentationController来显示UIViewController,就像UIAlertView一样.
但是当我创建自定义的UIViewController并使用UIPopoverPresentationController时.有全屏显示.
我想构建像http://cocoa.tumblr.com/post/92070238973/how-can-i-use-both-uipopoverpresentationcontroller这样的效果
我曾尝试设置preferredContentSize,但它仍然显示全屏.
我的代码如下:
- (void)viewDidLoad {
[super viewDidLoad];
contentVC = [UIViewController new];
contentVC.view.backgroundColor = [UIColor darkGrayColor];
contentVC.preferredContentSize = CGSizeMake(200, 200);
UIPopoverPresentationController *popPC = contentVC.popoverPresentationController;
popPC.delegate = self;
popPC.sourceView = self.view;
popPC.sourceRect = CGRectMake(0,0,0,0);
popPC.permittedArrowDirections = UIPopoverArrowDirectionAny;
}
- (IBAction)btnAction:(id)sender {
[self presentViewController:contentVC animated:NO completion:ni
}
-(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
{
return UIModalPresentationOverCurrentContext;
}
Run Code Online (Sandbox Code Playgroud)
有谁知道如何设置uiviewcontroller和UIPopoverPresentationController的大小,如网站效果?
我将在UIViewController中设置其他组件(现在只需设置backgroundcolor).
非常感谢你.