如何在不占据整个屏幕的 UIView 上使用 UIModalTransitionStylePartialCurl?

发布于 2024-09-26 06:39:36 字数 688 浏览 1 评论 0原文

在苹果 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

孤千羽 2024-10-03 06:39:37

使用如下内容覆盖 underMapViewControllerviewWillDisappear 方法:

- (void)viewWillDisappear:(BOOL)animated
{
    curlableMapViewController.view.frame = CGRectMake(0.f, 0.f, 320.f, 416.f);

    [super viewWillDisappear:animated];
}

curlableMapViewController 的视图大小更正为您指定的已知大小,例如,您可以先将其保存在 viewWillAppear 方法中。

Override the viewWillDisappear method of your underMapViewController with something like this:

- (void)viewWillDisappear:(BOOL)animated
{
    curlableMapViewController.view.frame = CGRectMake(0.f, 0.f, 320.f, 416.f);

    [super viewWillDisappear:animated];
}

That corrects the size of the view of the curlableMapViewController to the know size you specify, which you could save earlier in the viewWillAppear method, for example.

旧伤还要旧人安 2024-10-03 06:39:36

来自 文档

UIModalTransitionStylePartialCurl

当视图控制器出现时,当前视图的一个角会卷起以显示下面的模态视图。关闭时,卷曲的页面会自行展开回到模态视图的顶部。使用此转换呈现的模态视图本身无法呈现任何其他模态视图。

仅当父视图控制器呈现全屏视图并且您使用 UIModalPresentationFullScreen 模式呈现样式时才支持此过渡样式。尝试对父视图使用不同的外形规格或不同的呈现样式会触发异常。

尽管如此,我在使用全屏以外的其他演示文稿时没有遇到任何例外。我正在测试,我遇到了和你一样的问题。我发现如果我的 ParentViewController 的视图是 ImageView 并且我将内容模式设置为 UIViewContentModeCenter,则视图不会调整大小或移动。也许有一个解决方法,将当前视图保存为图像,将其放在顶部,进行卷曲,然后在关闭模态后,重新排列混乱的隐藏内容并删除顶部图像视图。我知道这听起来很疯狂,但如果我真的必须完成这个要求,我会尝试这样做。

希望这有帮助,豪尔赫。

From the Documentation:

UIModalTransitionStylePartialCurl

When the view controller is presented, one corner of the current view curls up to reveal the modal view underneath. On dismissal, the curled up page unfurls itself back on top of the modal view. A modal view presented using this transition is itself prevented from presenting any additional modal views.

This transition style is supported only if the parent view controller is presenting a full-screen view and you use the UIModalPresentationFullScreen modal presentation style. Attempting to use a different form factor for the parent view or a different presentation style triggers an exception.

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.

江城子 2024-10-03 06:39:36

像这样的事情怎么样:

    [UIView beginAnimations:@"PartialPageCurlEffect" context:nil];
    [UIView setAnimationDuration:0.3];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:myOldSubViewController.view cache:YES];

    [myOldSubViewController.view addSubview:myNewViewController.view];

    [UIView commitAnimations];

注意:对于某些视图,如果视图复杂且偏离中心,则可能会出现伪影。将 cache:YES 更改为 cache:NO 可能会修复。

How about something like this:

    [UIView beginAnimations:@"PartialPageCurlEffect" context:nil];
    [UIView setAnimationDuration:0.3];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:myOldSubViewController.view cache:YES];

    [myOldSubViewController.view addSubview:myNewViewController.view];

    [UIView commitAnimations];

Note: for some views if the views are complex and off-centre there could be artifacts. Changing cache:YES to cache:NO may fix with.

三人与歌 2024-10-03 06:39:36

正如 cprcrack 指出的那样,这并没有回答最初的问题。然而,它是有用的信息,因此考虑到这一点,我将把它留在这里。

这实际上比您想象的要简单得多。

我们将调用视图控制器 MapViewControllerSettingsViewController。您的问题是您想要剥离MapViewController部分(并且仅部分)以显示SettingsViewController

操作方法如下:

  • 对两个视图都使用全尺寸视图。
  • 仅将内容放在SettingsViewController视图的底部部分。
  • 使用 UIModalTransitionStylePartialCurl 在它们之间进行转换,就像您已经做的那样。

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 and SettingsViewController. Your problem is you want to peel back part (and only part) of MapViewController to show SettingsViewController.

Here's how you do it:

  • Use a full size view for both views.
  • Only put content on the bottom half of SettingsViewController's view.
  • Use 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 of SettingsViewController'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 back MapViewControllers 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.)

放肆 2024-10-03 06:39:36

我有一个轻微的打嗝,令人困惑

.modalTransitionStyle

.modalPresentationStyle

第一个出现在目标视图控制器上,例如,您想要在下面的那个。第二个发生在父视图控制器上,例如实际上被卷曲扭曲的那个。 OP 说对了,但我错了,在我弄清楚之前的 10 分钟里我很沮丧。把它扔到这篇文章上,以防它给别人我需要的头一巴掌。

I had a slight hiccough confusing

.modalTransitionStyle

and

.modalPresentationStyle

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.

葵雨 2024-10-03 06:39:36

我也遇到了这个问题。对我来说,直到模态视图被关闭之前,父视图的框架才被破坏。因此,我在关闭之前缓存了该帧,然后立即恢复了它。

CGRect frame = controllerWithModal.view.frame;
[controllerWithModal dismissModalViewControllerAnimated:YES];   
controllerWithModal.view.frame = frame;

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.

CGRect frame = controllerWithModal.view.frame;
[controllerWithModal dismissModalViewControllerAnimated:YES];   
controllerWithModal.view.frame = frame;
天涯离梦残月幽梦 2024-10-03 06:39:36

我也遇到了这个问题,但我解决了它..(不知道它的正确方式,但它的工作原理)

我想在滚动视图内有一个图像视图,当用户点击该滚动视图内的按钮时我想卷曲-向上滚动视图并在该位置显示表格视图。
所以我在滚动视图后面放置了一个表格视图,并最初将其设置为隐藏。当用户点击按钮时

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:frontView cache:YES];
[UIView commitAnimations];

在从视图中删除前视图之后就这样做了。
希望有帮助..

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

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:frontView cache:YES];
[UIView commitAnimations];

after that removed frontview from view.
Hope that helps..

泛泛之交 2024-10-03 06:39:36

我相信苹果的地图应用程序使用了未记录的转换: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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文