Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use UIModalTransitionStylePartialCurl on a UIView that does NOT take up the whole screen?

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];
like image 542
caecus314 Avatar asked Oct 03 '10 22:10

caecus314


4 Answers

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.

like image 159
Jorge Avatar answered Nov 10 '22 15:11

Jorge


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.

like image 31
Marius Avatar answered Nov 10 '22 17:11

Marius


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.)

like image 7
Steven Fisher Avatar answered Nov 10 '22 17:11

Steven Fisher


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.

like image 5
Chris Ladd Avatar answered Nov 10 '22 16:11

Chris Ladd