UIModalTransitionStylePartialCurl 与 UITabBarController [英] UIModalTransitionStylePartialCurl with UITabBarController

查看:19
本文介绍了UIModalTransitionStylePartialCurl 与 UITabBarController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题被问了很多,例如这里 但尽我所能请参阅尚未完整回答.

This question has been asked a lot e.g. here but as far as I can see is yet to be answered in full.

我有一个 UITabBarController 和一个 UINavigationController 作为其中一个选项卡的根 vc,它本身有一个 MKMapView 作为它的根 vc.我想要的行为是地图部分向上卷曲,同时保留标签栏(类似于地图应用).

I have a UITabBarController with a UINavigationController as the root vc for one of the tabs, which itself has a MKMapView as its root vc. The behaviour I want is for the map to partially curl upwards, while leaving the tab bar in place (similar to the Maps app).

到目前为止,我所做的只是让整个视图卷曲,这不是很好.

So far all I have managed to get working is for the whole view to curl, which isn't as nice.

我看到的解决方案是将 hidesBottomBarWhenPushed 属性设置为 NO,这是有道理的,但这似乎不起作用,(除非我做错了什么).

Solutions I have seen are to set the hidesBottomBarWhenPushed property to NO, which would make sense however this doesn't seem to work, (unless I am doing something wrong).

为清楚起见,我的代码如下:

For clarity, my code is as follows:

MyVC *aView = [MyVC init];
aView.modalTransitionStyle = UIModalTransitionStylePartialCurl;
aView.hidesBottomBarWhenPushed = NO;

对于演示部分,我尝试了以下两种选择,但似乎都不起作用:

For the presenting part, I have tried the two alternatives below, neither of which seem to work:

[self presentModalViewController:updateStatus animated:YES];
[[self navigationController] presentModalViewController:updateStatus animated:YES];

非常感谢任何帮助.

推荐答案

我已经在 StackOverflow(和 Internet)上搜索了这个问题的解决方案.这个问题已经被问过很多次了,但正如你所注意到的,从来没有得到充分的回答.许多解决方案提供了一个可接受的解决方案,如果它不重要,例如,下部工具栏是否也卷起.

I've scoured StackOverflow (and the Internet) for a solution to this problem. The question has been asked many times, but as you note, never sufficiently answered. Many solutions give an acceptable solution if it is unimportant whether, e.g., a lower toolbar curls up as well.

Others 提供了使用 UIView 动画/CoreAnimation 而不是 UIModalTransitionStylePartialCurl 作为模态过渡样式;这在最坏的情况下是 App Store 中不允许的解决方案,并且在最好的情况下与从 UIModalTransitionStylePartialCurl 获得的效果不太一样(例如,卷曲的形状不同).

Others have provided a solution using UIView animations / CoreAnimation rather than UIModalTransitionStylePartialCurl as a modal transition style; this is at worst a solution not allowed in the App Store, and at best is not quite the same effect as one gets from UIModalTransitionStylePartialCurl (e.g. the shape of the curl is different).

这些解决方案都没有提供模仿 Apple 在地图应用程序中的解决方案的答案(即,使用 UIModalTransitionStylePartialCurl 但在底部留下未卷曲的 UIToolbar屏幕).

None of these solutions have provided an answer that mimics Apple's solution in the Maps app (i.e., using UIModalTransitionStylePartialCurl but leaving an un-curled UIToolbar at the bottom of the screen).

我将继续这种不完整答案的传统,因为您询问的是 UITabBarController 而我的解决方案并没有专门解决这种情况.但是,它确实解决了我遇到的问题,即获得半页卷曲,底部有一个未卷曲的工具栏.

I will continue in this tradition of incomplete answers, since you ask about a UITabBarController and my solution doesn't specifically address that case. It does, however, solve the problem I had, which was to get a half page curl with an un-curled toolbar at the bottom.

必须有更优雅的方式来做到这一点,但我就是这样做的.

There must be a more elegant way to do this, but this is how I managed.

我的 AppDelegaterootViewControllerUIViewController 的子类,我将其称为 TAContainerViewController.TAContainerViewController 管理 a) 屏幕的实际内容(要卷曲的东西")、TAContentViewController 和 b) TAContentViewController<后面的内容/code>(例如设置),我将其称为 TAUnderCurlViewController.

The rootViewController of my AppDelegate is a subclass of UIViewController, which I'll call TAContainerViewController. TAContainerViewController manages a) the actual contents of the screen (the "stuff to be curled"), TAContentViewController, and b) the contents "behind" the TAContentViewController (e.g. settings), which I'll call TAUnderCurlViewController.

我的 TAContainerViewController 实例具有 TAContentViewControllerTAUnderCurlViewController 的属性.作为我的内容的 UIViewTAContentViewControllerview 属性的子视图;同样,用户在 curl 下看到的是 TAUnderCurlViewControllerview 属性.

My instance of TAContainerViewController had properties for a TAContentViewController and a TAUnderCurlViewController. The UIView that was my content was a subview of TAContentViewController's view property; likewise what the user sees under the curl is the view property of the TAUnderCurlViewController.

TAContainerViewControllerinit 方法中,我确保执行以下操作:

In the init method of TAContainerViewController I make sure to do the following:

    _underCurlVC.modalTransitionStyle = UIModalTransitionStylePartialCurl;

为了将内容卷曲以显示在页面下方,我设置了一个调用此代码的操作:

And to curl the contents to reveal under the page, I set up an action that calls this code:

    [self.contentVC presentModalViewController:self.underCurlVC animated:YES];`

其中 selfTAContainerViewControllercontentVCTAContentViewController 的实例,underCurlVCTAUnderCurlViewController 的一个实例.

where self is the TAContainerViewController, contentVC is an instance of TAContentViewController, and underCurlVC is an instance of TAUnderCurlViewController.

要关闭视图,只需 [self.contentVC dismissModalViewControllerAnimated:YES];.

当模态视图被关闭时,contentVC的框架似乎出现了一些奇怪的现象,所以我在模态视图被关闭时手动重置了框架.

Some strangeness seems to occur with the frame of contentVC when the modal view is dismissed, so I manually reset the frame when the modal view is dismissed.

我在 Github 上发布了一个包含更多详细信息的示例项目.希望有人可以把它变成一个更优雅的解决方案,或者扩展它以使用 UINavigationControllerUITabBarController.我认为诀窍是将视图控制器从 Cocoa 子类中定义良好的关系中拉出来,所以也许将那些特殊的视图控制器子类化就可以了.

I've posted a sample project with more details on Github. Hopefully someone can take this and turn it into a slightly more elegant solution, or expand it to work with a UINavigationController or UITabBarController. I think the trick is to pull the View Controllers out of the well-defined relationships in the Cocoa subclasses, so maybe subclassing those specialty View Controllers would do it.

这篇关于UIModalTransitionStylePartialCurl 与 UITabBarController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆