iPhone视图切换 - 卷曲过渡

时间:2009-12-13 11:35:40

标签: iphone animation transition

我正在使用以下代码在我的应用中加载视图:

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

}

如何通过卷曲/卷曲过渡加载它?

提前致谢,

亚辛

3 个答案:

答案 0 :(得分:7)

使用您在那里显示的代码,您可以设置imagePickerView的modalTransitionStyle属性。但是,您的可能值(来自SDK文档):

  • UIModalTransitionStyleCoverVertical :显示视图控制器时,其视图会从屏幕底部向上滑动。在解雇时,视图向下滑动。这是默认的过渡样式。
  • UIModalTransitionStyleFlipHorizo​​ntal :当呈现视图控制器时,当前视图从右向左启动水平3D翻转,从而导致新视图的显示,就像它在背面一样以前的观点。在解雇时,翻转从左到右发生,返回到原始视图。
  • UIModalTransitionStyleCrossDissolve :显示视图控制器时,当新视图同时淡入时,当前视图淡出。在解雇时,使用类似的交叉淡入淡出来返回原始视图。

您的其他选择要求您获得更多的发烧友。假设navigationController是应用程序的根视图控制器,它存储在名为navigationController的应用程序委托的属性中。您可以实现以下方法:

- (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;
    }
}

答案 1 :(得分:4)

现在可以在OS 3.2及更高版本中轻松使用;你这样做: -

// 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] init];
    legend.modalTransitionStyle = UIModalTransitionStylePartialCurl;
    legend.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentModalViewController:legend animated:YES];  
    [legend release];
} 

答案 2 :(得分:1)

我喜欢这些潜在的问题。我做了很多成功,你使用视图转换动画来显示新视图,然后在completionHandler中显示presentModalViewController,以便将新视图视为模态视图。

    UIView *container = self.view.window;
    [self.theNewViewController viewWillAppear:YES];
    [UIView transitionWithView:container
                  duration:kAnimationViewTransition 
                   options:UIViewAnimationOptionTransitionCurlUp
                animations:^{
                    [self.navigationController.view removeFromSuperview];
                    [container addSubview: self.theNewViewController.view];
                } 
                completion:^(BOOL finished) {
                    [self presentModalViewController:self.theNewViewController animated:NO];
                }
 ];