是否可以在屏幕上显示UIPopover控制器?
我在我的应用程序中可以稍微移动一个小视图,我希望UIPopoverController可以随它移动,而不必在每次移动时重新呈现UIPopoverController。这可能吗?UIPopoverController可以在屏幕上移动吗?
回答
从iOS 9开始,“UIPopoverController已过时,现在将Popovers实现为UIViewController演示文稿,使用UIModalPresentationPopover和UIPopoverPresentationController的模态演示风格。
使用以下内容显示弹出窗口。您可能能够更改sourceRect和sourceView的值,但这不是API行为。
DetailViewController *detailVC = self.detailViewController;
detailVC.preferredContentSize = CGSizeMake(420, 92);
detailVC.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *presController = detailVC.popoverPresentationController;
if (presController) {
presController.delegate = detailVC;
presController.barButtonItem = self.detailButton;
presController.sourceRect = self.view.frame;
presController.sourceView = self.view;
presController.permittedArrowDirections = UIPopoverArrowDirectionAny;
}
[self presentViewController: detailVC animated:YES completion:^{
}];
取而代之的是,我建议保留对popover的视图控制器的引用,关闭popover并重新呈现。
DetailViewController *detailVC = self.detailViewController;
[self dismissViewControllerAnimated:NO completion:^{
UIPopoverPresentationController *presController = detailVC.popoverPresentationController;
if (presController) {
presController.delegate = detailVC;
presController.barButtonItem = self.detailButton;
presController.sourceRect = self.view.frame; //Update frame
presController.sourceView = self.view;
presController.permittedArrowDirections = UIPopoverArrowDirectionAny;
}
[self presentViewController: detailVC animated:NO completion:^{
}];
}];
我一直在为此投票。如果您打算为接受的答案投票,请提供帮助并发表评论。 – 2013-07-19 17:12:16
“创建你自己的”不是我要找的答案 – Loukas 2016-03-18 14:06:17
@Loukas我希望你会更喜欢这个新的答案。如果UIPopoverPresentationController没有提供所需的功能,您将不得不重新创建UIPopoverController,因为API不是很灵活。 – 2016-03-19 13:42:43
不,你不能。这不是做这件事的方法。
pover presentPopoverFromRect:
在评论中提到,但注意到
目前
你不能没有重绘代表。
您可以跟踪用户在屏幕上的触摸情况,并使用presentPopoverFromRect:
来重新显示弹出窗口。
这是值得一试的,但我想这样做可能有点贵。我相信,当你解雇它并重新实现它时,正在进行的资源分配很多,这可能会对系统造成严重的负担。 – 2011-05-07 01:35:48
这是事实,但那是一个良好的内存管理进场的地方。特别是在iPad上,你有更多的记忆可供玩耍。 – WrightsCS 2011-05-07 01:41:30
您可以重新调用presentPopoverFromRect。
见http://developer.apple.com/library/ios/#qa/qa1694/_index.html
- 1. 我可以“移动”屏幕,但屏幕上的物体仍在移动吗?
- 2. CSS3过渡:它可以在屏幕上移动东西吗?
- 3. 在屏幕上移动UIbutton
- 4. MKMapView在屏幕上移动
- 5. 将屏幕移动到屏幕上
- 6. 在移动屏幕上获取可移动屏幕上的可见部分(放大图像),在HTML中
- 7. 我可以在屏幕上移动pygame游戏窗口(pygame)
- 8. 在iphone上的屏幕上移动UIView
- 9. AS3 - 在屏幕上移动MovieClip
- 10. 在屏幕上移动图像
- 11. 在屏幕上移动鼠标光标
- 12. Javascript在屏幕上移动目标?
- 13. WPF在屏幕上移动的边框
- 14. 在屏幕上移动立体视频
- 15. 在屏幕IOS上移动图像?
- 16. 使用NSMutablearray在屏幕上移动UILabels
- 17. 如何在屏幕上移动对象
- 18. 如何在屏幕上移动图像?
- 19. 使对象在屏幕上移动iphone?
- 20. 在屏幕上选择并移动Qwidget
- 21. 随机移动星星在屏幕上
- 22. Media Projection api可以在棒棒糖主屏幕上截取屏幕截图吗?
- 23. 滑动屏幕上的移动物体的欢迎屏幕
- 24. 是否可以在Android主屏幕上制作动画移动小部件?
- 25. 我可以将活动终端会话移动到屏幕会话吗?
- 26. 向上移动屏幕上的矩形
- 27. 在android中移动图像部分在屏幕上移动
- 28. 玩家可以移出屏幕?
- 29. 隐藏ADBannerView。将它移出屏幕可以吗?
- 30. 当导航在屏幕上变化时,在另一个屏幕上移动div
是不是'[酥料饼presentPopoverFromRect:]'为你工作? – 2011-05-06 21:54:58
现在的问题是,他是否可以移动popOver一旦提交 – Sid 2011-05-06 23:23:34
我不认为它的位置可以直接更改。但是,如果您在不打开它的情况下调用presentPopoverFromRect,它应该“移动”。 – Anna 2011-05-07 00:46:15