如何在不占据整个屏幕的 UIView 上使用 UIModalTransitionStylePartialCurl?
在苹果 iPhone 的官方地图应用程序中,右下角有一个小的“翻页”按钮。当您按下它时,地图本身会剥离以显示一些选项。我想在我自己的应用程序中复制这种效果。
我正在尝试使用 UIModalTransitionStylePartialCurl (在 SDK 3.2 中添加)。就布局而言,我的应用程序与 Apple 的官方地图应用程序几乎一模一样。我可以轻松地将整个屏幕剥离,露出下面的另一个视图,但我不想要这样。我只想将地图视图剥离。
为了创建这种效果,您必须有一个执行转换的 UIViewController。如果我将这个 UIViewController 的视图设置为屏幕上某个位置的一个小子视图,该子视图不占据整个屏幕,我就可以只将该子视图剥离。那太棒了!然而,在过渡的第二部分之后(当页面回落到原位时),视图永远不会回到它们开始的位置。要么剥离的视图将从其原始位置移动,要么显示的视图将扩展以占据整个屏幕。
我犯了什么明显的错误吗?我真的很感激任何帮助!
我使用的代码非常简单。基本上就是:
underMapViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[curlableMapViewController presentModalViewController:underMapViewController animated:YES];
In Apple's official Maps app for the iPhone, there is a small 'page curl' button in the lower-right corner. When you press it, the map itself peels back to reveal some options. I would like to duplicate this effect in my own app.
I'm trying to use UIModalTransitionStylePartialCurl (Added in SDK 3.2). In terms of its layout, my app resembles Apple's official Maps app almost exactly. I can easily get the ENTIRE screen to peel back, revealing another view underneath, but I don't want this. I want ONLY the map view to peel back.
In order to create this effect, you must have a UIViewController that will perform the transition. If I set this UIViewController's view to a small subview somewhere on the screen that does not take up the entire screen, I can get just that subview to peel back. That's great! However, after the second part of the transition (when the page falls back into place), the views are never where they started. Either the view that peeled back will have moved from its original position, or the view that was revealed will have expanded to take up the entire screen.
Is there any obvious mistake that I'm making? I would really appreciate any help!
The code I'm using is really simple. It's basically just:
underMapViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[curlableMapViewController presentModalViewController:underMapViewController animated:YES];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
使用如下内容覆盖
underMapViewController
的viewWillDisappear
方法:将
curlableMapViewController
的视图大小更正为您指定的已知大小,例如,您可以先将其保存在viewWillAppear
方法中。Override the
viewWillDisappear
method of yourunderMapViewController
with something like this:That corrects the size of the view of the
curlableMapViewController
to the know size you specify, which you could save earlier in theviewWillAppear
method, for example.来自 文档:
尽管如此,我在使用全屏以外的其他演示文稿时没有遇到任何例外。我正在测试,我遇到了和你一样的问题。我发现如果我的 ParentViewController 的视图是 ImageView 并且我将内容模式设置为 UIViewContentModeCenter,则视图不会调整大小或移动。也许有一个解决方法,将当前视图保存为图像,将其放在顶部,进行卷曲,然后在关闭模态后,重新排列混乱的隐藏内容并删除顶部图像视图。我知道这听起来很疯狂,但如果我真的必须完成这个要求,我会尝试这样做。
希望这有帮助,豪尔赫。
From the Documentation:
Although, I haven't got any exception using other presentations than full screen. I was testing out and I get the same problem as you. I found that if my ParentViewController's view is an ImageView and I set the content mode to UIViewContentModeCenter, the view is not resized or moved. Maybe there is a workaround by saving your current view as an image, put it at the top, make the curl, and after you dismiss your modal, rearrange the messed hidden stuff and remove the top image view. I know that it sounds crazy but that is what I would try if I really had to accomplish that requirement.
Hope this helps, Jorge.
像这样的事情怎么样:
注意:对于某些视图,如果视图复杂且偏离中心,则可能会出现伪影。将
cache:YES
更改为cache:NO
可能会修复。How about something like this:
Note: for some views if the views are complex and off-centre there could be artifacts. Changing
cache:YES
tocache:NO
may fix with.正如 cprcrack 指出的那样,这并没有回答最初的问题。然而,它是有用的信息,因此考虑到这一点,我将把它留在这里。
这实际上比您想象的要简单得多。
我们将调用视图控制器
MapViewController
和SettingsViewController
。您的问题是您想要剥离MapViewController
的部分(并且仅部分)以显示SettingsViewController
。操作方法如下:
SettingsViewController
视图的底部部分。iOS 会检测到您已自动完成此操作,并且只会将 MapViewController 的视图向后剥离到
SettingsViewController 视图的下半部分,这是您所有内容的所在是。
如果您将内容放在
SettingsViewController
视图的上半部分,iOS 将检测到这一点,并完全剥离MapViewController
视图。摘要:仅将内容放在新视图的下半部分。 iOS 会解决这个问题。
(我认为这没有在任何地方记录,抱歉。)
As cprcrack points out, this doesn't answer the original question. However, it's useful information, so with that in mind I'm going to leave it here.
This is actually much simpler than you'd guess.
We'll call the view controllers
MapViewController
andSettingsViewController
. Your problem is you want to peel back part (and only part) ofMapViewController
to showSettingsViewController
.Here's how you do it:
SettingsViewController
's view.UIModalTransitionStylePartialCurl
to transition between them, like you already are.iOS will detect that you've done this automatically and only peel
MapViewController
's view back far enough to the bottom half ofSettingsViewController
's view, which is where all your content is.If you put content in the top half of
SettingsViewController
's view, iOS will detect that and peel backMapViewController
s view all the way instead.Summary: Put content only in the bottom half of your new view. iOS will figure it out.
(I don't think this is documented anywhere, sorry.)
我有一个轻微的打嗝,令人困惑
,
第一个出现在目标视图控制器上,例如,您想要在下面的那个。第二个发生在父视图控制器上,例如实际上被卷曲扭曲的那个。 OP 说对了,但我错了,在我弄清楚之前的 10 分钟里我很沮丧。把它扔到这篇文章上,以防它给别人我需要的头一巴掌。
I had a slight hiccough confusing
and
The first one goes on the TARGET viewController, e.g., the one you want underneath. The second goes on the PARENT viewController, e.g. the one that actually gets distorted by the curl. The OP got this right, but I got it wrong, and it was a frustrating 10 minutes before I figured it out. Throwing it on this post in case it gives someone else the head slap I needed.
我也遇到了这个问题。对我来说,直到模态视图被关闭之前,父视图的框架才被破坏。因此,我在关闭之前缓存了该帧,然后立即恢复了它。
I ran into this problem as well. For me the frame of the parent view wasn't mangled until the modal view was dismissed. So I cached the frame before dismissing then restored it right after.
我也遇到了这个问题,但我解决了它..(不知道它的正确方式,但它的工作原理)
我想在滚动视图内有一个图像视图,当用户点击该滚动视图内的按钮时我想卷曲-向上滚动视图并在该位置显示表格视图。
所以我在滚动视图后面放置了一个表格视图,并最初将其设置为隐藏。当用户点击按钮时
我
在从视图中删除前视图之后就这样做了。
希望有帮助..
Me too had this problem,but i solved it..(dont know its the right way,but its working)
I wanted to had an imageview inside a scrollview,and when the user taps a button inside that scroll view i wanted to curl-up the scroll view and show a tableview in that place.
So i placed a tableview behind scrollview and initialy set it to hidden.when the user taps button
i did
after that removed frontview from view.
Hope that helps..
我相信苹果的地图应用程序使用了未记录的转换:mapCurl 和mapUncurl。我不确定有什么方法可以完全达到 caecus314 想要的效果(这也是我一直试图复制的效果)。
UIModalTransitionStylePartialCurl 将卷起第一个视图的整个底部,包括工具栏,这不像苹果的地图应用程序,后者仅卷起地图并将工具栏保留在原处。
据我所知,没有办法只卷曲地图。
I believe that Apple's Maps application uses undocumented transitions: mapCurl and mapUncurl. I am not sure there is any way to do exactly what caecus314 wants (which is also the effect I have been trying to duplicate).
UIModalTransitionStylePartialCurl will curl up the whole bottom part of the first view, including the toolbar, which is unlike Apple's Maps app, which only curls up the map and leaves the toolbar in place.
As far as I can tell there is no way to only curl up the map.