我设定了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;
}
有没有人知道如何设置UIViewController和UIPopoverPresentationController的大小,就像网站效果那样?
我将在UIViewController中设置其他组件(现在只设置背景颜色)。
非常感谢。
adaptivePresentationStyleForPresentationController:
的使用--https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIAdaptivePresentationControllerDelegate_protocol/index.html#//apple_ref/occ/intfm/UIAdaptivePresentationControllerDelegate/adaptivePresentationStyleForPresentationController: - Lyndsey Scott