UIModalTransitionStylePartialCurl与UITabBarController [英] UIModalTransitionStylePartialCurl with UITabBarController

查看:222
本文介绍了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.

其他使用 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.

我的 rootViewController AppDelegate UIViewController 的子类,我将其称为 TAContainerViewController TAContainerViewController 管理a)屏幕的实际内容(要卷曲的东西), TAContentViewController 和b ) TAContentViewController 后面的内容(例如设置),我将其称为 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实例具有 TAContentViewController 的属性和 TAUnderCurlViewController UIView 这是我的内容是 TAContentViewController的子视图视图财产;同样用户在curl下看到的是 TAUnderCurlViewController的视图属性

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.

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

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];`

其中 self TAContainerViewController contentVC TAContentViewController 的实例,而 underCurlVC 是一个 TAUnderCurlViewController 的实例。

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上。希望有人可以把它变成一个稍微优雅的解决方案,或者扩展它以使用 UINavigationController UITabBarController 。我认为诀窍是将视图控制器从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天全站免登陆