带有模态 UIViewController 的透明背景
我有一个困境,我想向用户呈现一个半透明的视图。
我通过实验发现,如果我只是将透明视图推到导航控制器堆栈的顶部,它不会呈现我想要的透明度级别。因此,我决定简单地将视图添加为堆栈顶部当前视图的子视图。
该解决方案有效,下面的视图仍然可见,并且视图是“半模态”的。问题是,如果父视图继承自 UITableViewController (就像我的那样),那么我“推”到它上面的视图不会覆盖顶部的导航栏。
我真的不想陷入每次推送此视图时都被迫启用/禁用导航栏上的控件的情况,所以我想知道是否有人知道我可以使用的任何解决方案,以便该视图我推到 UITableViewController 上实际上会“推过”导航栏吗?
I have a dilema, I want to present to the user a semi-transparent view.
I found out by experimenting that if I simply pushed the transparent view to the top of my NavigationController's stack, that it would not render the transparency level I wanted. So I decided to simply add the view as a subview of the current view at the top of the stack.
This solution works, the view below is still visible, and the View is 'semi-modal'. The problem is, if the parent view inherits from UITableViewController (as mine does), then the view I 'push' onto it, does not cover the navigation bar at the top.
I really don't want to get into a situation where I am forced to enable / disable controls on the navigation bar every time I push this view, so I was wondering, if anyone knew of any solutions that I could use so that the view I push onto the UITableViewController will actually 'push over' the navigation bar?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
有趣的是,我昨天也在做同样的事情。不幸的是,这似乎是不可能的。一旦模态视图控制器就位,之前的视图就会隐藏。
请参阅有关该主题的上一个问题。
您仍然可以使用已设置的视图控制器和 NIB 文件 - 这是我的示例代码
您将需要在模式视图控制器中存储对父视图控制器的引用,以便您可以访问
-hide
方法。我通过一位代表做到了这一点。如果你想让它从屏幕底部向上动画,向
-show
和-hide
添加一些动画也很容易 - 我只是懒得这么做这。Funny, I was just doing the same thing yesterday. Unfortunately it seems to be impossible. Once the modal view controller is in place, the previous view becomes hidden.
See this previous question on the topic.
You can still use the view controller and NIB files you have set up - here's my sample code
You will need to store a reference to the parent view controller in the modal view controller so that you can access the
-hide
method. I did this through a delegate.It would also be easy to add some animation to
-show
and-hide
if you want it to animate up from the bottom of the screen - I was just too lazy to do this.iOS 8 添加了
UIModalPresentationOverFullScreen
演示风格。将其设置为呈现的视图控制器的modalPresentationStyle
。对于更高级的需求,请考虑创建自定义演示控制器。iOS 8 added the
UIModalPresentationOverFullScreen
presentation style. Set this as the presented view controller’smodalPresentationStyle
. For more advanced needs, look into creating a custom presentation controller.现在有一种方法可以使用 iOS7 自定义过渡来实现此目的:
要创建自定义过渡,您需要两件事:
)(实现
)您可以在本教程中找到有关自定义过渡的更多信息:http://www.doubleencore.com/2013/09/ios-7-custom-transitions/
There is now a way to achieve this using iOS7 custom transitions :
To create your custom transition, you need 2 things :
<UIViewControllerTransitionDelegate>
)(implementing
<UIViewControllerAnimatedTransitioning>
)You can find more informations on custom transitions in this tutorial : http://www.doubleencore.com/2013/09/ios-7-custom-transitions/
试试这个:
Try this:
您是否尝试过循环模态视图控制器的子视图并将每个视图的背景颜色设置为清除?这是一个DFS递归函数。
要使用它,请
在
viewDidLoad
中调用:。Have you tried looping over the Modal View Controller's subviews and setting the background color to clear for every view? This is a DFS recursive function.
To use it call:
in
viewDidLoad
.这就能解决问题……试试这个。
这样视图将是全屏的,与 UIModalPresentationFormSheet 不同。
This will do the trick.. Try this one.
So that the view will be full screen unlike UIModalPresentationFormSheet..