Cha*_*ish 5 ipad ios uistoryboard uistoryboardsegue
所以我有我的主视图控制器.该视图控制器有一个带有故事板segue的条形按钮项目,其类型设置为Present As Popover.
这一切都按预期工作.但是当您点击该弹出窗口控制器中的另一个按钮时,它会全屏显示视图.我希望它在popover中显示.就像在现有的popover界限之上推/显示一样.
我怎样才能做到这一点?
我只想在iPad上这种行为.但我认为默认情况下这样做.
编辑
我更喜欢在故事板中完成所有操作,但我愿意使用Swift代码,如果这是必需的.
创建一个IBAction你的UIBarButtonItem,并在行动:
- (IBAction)popupAction:(UIBarButtonItem *)sender {
UIViewController *vc = [[UIViewController alloc] init]; // I don't use segue
vc.view.backgroundColor = [UIColor grayColor];
vc.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *popvc = vc.popoverPresentationController;
popvc.delegate = self;
popvc.permittedArrowDirections = UIPopoverArrowDirectionAny;
popvc.barButtonItem = sender; // if UIBarButtonItem
// if view
// popvc.sourceView = sender;
// popvc.sourceRect = sender.bounds;
vc.preferredContentSize = CGSizeMake(200, 200);
[self presentViewController:vc animated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
而且UIPopoverPresentationControllerDelegate:
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller traitCollection:(UITraitCollection *)traitCollection{
return UIModalPresentationNone;
}
- (BOOL)popoverPresentationControllerShouldDismissPopover:(UIPopoverPresentationController *)popoverPresentationController{
return YES;
}
Run Code Online (Sandbox Code Playgroud)
迅速:
@IBAction func popupAction(_ sender: UIBarButtonItem) {
let vc = UIViewController.init()
vc.view.backgroundColor = UIColor.gray
vc.modalPresentationStyle = UIModalPresentationStyle.popover
let popvc = vc.popoverPresentationController
popvc?.delegate = self
popvc?.permittedArrowDirections = UIPopoverArrowDirection.any
popvc?.barButtonItem = sender
vc.preferredContentSize = CGSize.init(width: 200, height: 200)
self.present(vc, animated: true, completion: nil)
}
func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
return UIModalPresentationStyle.none
}
func popoverPresentationControllerShouldDismissPopover(_ popoverPresentationController: UIPopoverPresentationController) -> Bool {
return true
}
Run Code Online (Sandbox Code Playgroud)
这适用于iPad和iPhone.
结果:

在弹出框控制器中弹出另一个viewController:

这只适用于Storyboard.
1)从UIBarButtonItem创建一个UIViewController(蓝色)和ctrl + drag(鼠标)到UIViewController并选择"present as Popover"(就像你做的那样).
2)单击UIViewController(蓝色)并单击Editor-> embed in-> Navigation Controller(这将是让下一个控制器保持在弹出窗口中的技巧)
3)创建第二个UIViewController(绿色)
4)在第一个UIViewController中创建一个UIButton(蓝色)并按住Ctrl键从按钮拖动到第二个UIViewController(绿色)并选择"show"
最后它应该在Storyboard中看起来像这样:
结果如下:
如果你想要没有navigationBar的PopOver,你可以在蓝色控制器中使用:
self.navigationController?.isNavigationBarHidden = true
Run Code Online (Sandbox Code Playgroud)
并从绿色到蓝色视图返回,您可以在绿色控制器中使用:
@IBAction func backToBlueController(sender: UIButton) {
self.navigationController?.popViewController(animated: true)
}
Run Code Online (Sandbox Code Playgroud)
额外:
如果您不想使用popUp,您还可以将segue种类从barButtonItem更改为navigationController
目前模态
和演示到类似的东西
表单
在故事板中.
一目了然,即使您不需要navigationBar,也应始终使用UINavigationController来管理导航,因为导航控制器会为您提供一个导航堆栈,您可以从中弹出并推入导航堆栈.
| 归档时间: |
|
| 查看次数: |
10433 次 |
| 最近记录: |