views:

1793

answers:

2

I'm loading a view in my app with the following code:

- (void)showPicker {
ImagePickerViewController *imagePickerView = [[ImagePickerViewController alloc] initWithNibName:@"ImagePickerViewController" bundle:nil];
[self.navigationController presentModalViewController:imagePickerView animated:YES];

}

How can I load it with a curl up/curl down transition?

Thanks in advance,

Yassin

+6  A: 

Using the code you showed there, you could set the modalTransitionStyle property of imagePickerView. But, your possible values are (from the SDK documentation):

  • UIModalTransitionStyleCoverVertical: When the view controller is presented, its view slides up from the bottom of the screen. On dismissal, the view slides back down. This is the default transition style.
  • UIModalTransitionStyleFlipHorizontal: When the view controller is presented, the current view initiates a horizontal 3D flip from right-to-left, resulting in the revealing of the new view as if it were on the back of the previous view. On dismissal, the flip occurs from left-to-right, returning to the original view.
  • UIModalTransitionStyleCrossDissolve: When the view controller is presented, the current view fades out while the new view fades in at the same time. On dismissal, a similar type of cross-fade is used to return to the original view.

Your other option requires you to get a lot fancier. Let's assume the navigationController is the the root view controller of the application, and it's stored in a property of your application delegate called navigationController. You could implement the following methods:

- (void)curlInViewController:(UIViewController *)viewController {
    self.curledViewController = viewController;

    [UIView beginAnimations:@"curlInView" context:nil];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.window cache:YES];
    [self.navigationViewController.view removeFromSuperview];
    [self.window addSubview:viewController.view];
    [UIView commitAnimations];
}

- (void)curlOutViewController {
    [UIView beginAnimations:@"curlOutView" context:nil];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.window cache:YES];
    [self.curledViewController removeFromSuperview];
    [self.window addSubview:navigationController.view];
    [UIView commitAnimations];
}

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
    if([animationID isEqualToString:@"curlOutView"]) {
        self.curlViewController = nil;
    }
}
Jacques
Great, thank you very much. I'm using the modalTransitionStyle property now, and tomorrow I'm going to implement the methods you posted above.
Yassin
+1  A: 

This is now easily available in OS 3.2 and above; you do it like this: --

// if the legend button is tapped, curl up the map view to display the legend view underneath. (IBAction) legendButtonPressed:(id) sender {

UIViewController *legend = LegendViewController alloc; legend.modalTransitionStyle = UIModalTransitionStylePartialCurl; self presentModalViewController:legend animated:YES;

}

Donal O'Danachair