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

社会主义新天地 提交于 2019-12-02 15:12:18
Jorge

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.

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.

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

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.

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;

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

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!