如何使用 Xcode Storyboards 创建 Popover
如何在 iPad Storyboard 中为 iOS 5.0+ 应用程序创建弹出框?
Xcode 项目模板(实用程序应用程序)已经有了一个设置,但我似乎不明白 Apple 是如何让它工作的。我试图模仿它,但只出现错误。我什至查看了苹果的开发网站,但只得到了导致警告和构建错误的过时代码。
我有一个 CBMainView
和一个 CBMasterView
(已包含的主视图除外),以及一个 UIToolbar
和一个 UIToolbarButton< /代码>。我需要用户点击
UIToolbar
上的按钮,然后出现我的 320x300 Popover (CBMasterView
)。
如何使用 Xcode Storyboard 做到这一点?教程、答案、代码或链接都值得赞赏!
How can I create a popover in an iPad Storyboard for an iOS 5.0+ app?
There's already one setup with the Xcode Project Template (Utility App), but I can't seem to figure out how Apple got it to work. I tried to mimic it, but only got errors. I even looked on Apple's Dev Site, but only got out-dated code that resulted in warnings and build errors.
I have a CBMainView
and a CBMasterView
(with the exception of the master view already included), and a UIToolbar
with a UIToolbarButton
. I need the user to tap the button on the UIToolbar
, and up comes my 320x300 Popover (CBMasterView
).
How can I do this with Xcode Storyboards? Tutorials, answers, code, or links are all appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 iOS 5 之前,人们需要通过模态演示(和一堆代码)使用第一响应者来显示另一个
UIViewController
。要在 Xcode 的 Storyboard 模式 (iOS 5+) 中创建弹出窗口,请使用
UIButton
或UIToolbarButton
并在按钮和UIViewController
之间创建 Storyboard Segue您想要弹出。在按钮和另一个 UIViewController 之间创建 Segue 很简单。操作方法如下:
UIViewController
。您应该会看到一条浅蓝色线出现,从按钮延伸到鼠标尖端。将蓝线拖到所选的 ViewController 后,会出现一个黑色的小菜单。此菜单显示不同的 segue 选项。选择
弹出框
。如果一切都正确完成,当选择按钮时,此 Segue 应该在连接检查器中可见:
您创建的
UIViewController
还应该具有小于全屏的自定义尺寸。您可以通过选择视图控制器并将其尺寸属性设置为freeform
或master
(320 x 850)来设置自定义尺寸。Before iOS 5, one would've needed to display another
UIViewController
using the First Responder via a Modal presentation (and a pile of code).To create a popover in Xcode's Storyboard Mode (iOS 5+) use a
UIButton
orUIToolbarButton
and create a Storyboard Segue between the button and theUIViewController
that you want to pop-over.Creating a segue between a button and another
UIViewController
is simple. Here's how:UIViewController
of choice. You should see a light blue line appear that extends from the button to the tip of your mouse.After dragging the blue line to the ViewController of choice a small black menu will appear. This menu displays the different segue options. Select
Popover
.If everything was done correctly, this segue should be visible in the Connections Inspector when the button is selected:
The
UIViewController
you create should also have a custom size that is smaller than the full screen. You can set a custom size by selecting the View Controller and setting its size property tofreeform
, ormaster
(320 x 850).我也在寻找这个问题的答案。我确实使用 NSNotification 解决了这个问题。
具体方法如下:
显示弹出窗口的视图控制器应注册以接收通知:
languageSetup
是将要调用的函数,SPVWChangeLanguage
是您将在您的弹出视图控制器我在
viewDidAppear
中添加了这一行现在,当用户在表中选择某些内容时,在弹出视图控制器中添加这一行:
在关闭弹出窗口之前:
仅此而已。选择器 languageSetup (在我的例子中)将被调用。当视图控制器消失时,请务必删除通知:
我在 viewWillDisappear 中执行此操作,
我认为一定有更简单的方法。但至少,这个对我有用。
I'm also looking for the answer to this problem. I did solve it using NSNotification.
Here's how:
The View Controller that displays the popup should register to receive the notification:
languageSetup
is the function that will be called,SPVWChangeLanguage
is a string that you will define in your popup view controllerI added this line in
viewDidAppear
Now in your popup view controller add this line when the user selects something in the table:
before dismissing the popup:
That's all. The selector languageSetup (in my case) will be called. Be sure to remove the notification when your view controller goes away:
I do it in
viewWillDisappear
I think there must be an easier way. But at least, this one works for me.
如果你在IOS8上使用storyboard,请看一下这篇文章,为我解答!
如何在顶部呈现模式Swift 中的当前视图
简而言之:您创建一个单独的弹出视图,为背景提供低(或无)不透明度的颜色,然后从主视图连接到弹出视图,带有模态序列。
然后在故事板中,单击segue,然后在属性检查器中:将演示文稿更改为“在当前上下文上”(如果您使用大于0的不透明度,则可能会过渡到交叉溶解)
到目前为止我见过的最简单的方法!
If you use storyboard with IOS8, take a look at this post, answered it for me!
How to present a modal atop the current view in Swift
In short: You make a separate popup view, give the background a color with low (or none) opacity, and connect from your main view to the popup view, with a modal segue.
Then in storyboard, click on the segue, and then in the attibute inspector: change presentation to "over current context" (and maybe transition to cross dissolve, if you use an opacity that is more than 0)
Easiest way i have seen so far!