你好我想在一个主视图上呈现一个控制器具有弹出功能的控制器可以任何人我这个吗? 我已经尝试过以下代码,但它在所有视图中都是comin,我希望它在视图中心的小尺寸。 这是下面的代码
Login *popoverController = [[Login alloc] init];
popoverController.popoverPresentationController.sourceView = self.view; //The view containing the anchor rectangle for the popover.
popoverController.popoverPresentationController.sourceRect = CGRectMake(384, 40, 40, 40); //The rectangle in the specified view in which to anchor the popover.
[self presentViewController:popoverController animated:YES completion:nil];
答案 0 :(得分:1)
您可以使用容器视图。将容器视图添加到父视图,并在容器视图中添加其他视图控制器。
self.addChildViewController(vc)
vc.view.frame = CGRectMake(0, 0, self.container.frame.size.width, self.container.frame.size.height);
self.container.addSubview(vc.view)
vc.didMoveToParentViewController(self)
答案 1 :(得分:0)
let popOverView = self.popoverController.popoverPresentationController
popOverView!.delegate = self
if popOverView!.sourceView == nil
{
popOverView!.sourceView = self.view
self.popoverController.superView = self
}
popOverView!.sourceRect = CGRectMake(“X-Define”, ““Y-Define”, “Width”, “Height”)
popOverView!.passthroughViews = [self.view]
self.presentViewController(self.popoverController, animated: true, completion: nil)
答案 2 :(得分:0)
试试这个,我希望它可以帮到你......
<。>文件中的
假设您的故事板segue标识符名称为showPopover
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSString *identifier = segue.identifier;
if ([identifier isEqualToString:@"showPopover"]) {
UIViewController *dvc = segue.destinationViewController;
dvc.preferredContentSize = CGSizeMake(180,130);
UIPopoverPresentationController *ppc = dvc.popoverPresentationController;
if (ppc) {
ppc.delegate = self;
}
}
}
另外添加:
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
return UIModalPresentationNone;
}