使用水平翻转呈现formheet模态ViewController

时间:2011-09-12 12:55:15

标签: cocoa-touch ipad

我目前在formSheet样式中显示了一个带有coverVertical动画的模态UIViewController。我试图从它呈现另一个模态UIViewController,使用currentContext作为演示样式,flipHorizo​​ntal用于动画样式。它确实有效,但翻转后面有一个坚实的白色白色背景。有关如何使用formSheet样式中预先存在的模态UIViewController的flipHorizo​​ntal样式成功呈现另一个表单模式UIViewController的任何建议,请欣赏!谢谢

代码:

// Loading of first modalVC
- (void)showModalVC {

    Modal1VC *modal1VC = [[Modal1VC alloc] init];
    modal1VC.modalPresentationStyle = UIModalPresentationFormSheet;
    modal1VC.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentModalViewController:modal1VC animated:YES];
    [modal1VC release];

    modal1VC.view.superview.bounds = CGRectMake(0, 0, 400, 400);
}

// Loading of second modalVC in Modal1VC
- (void)buttonTapped:(id)sender {

    UIViewController *modal2VC = [[UIViewController alloc] init];
    modal2VC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    modal2VC.modalPresentationStyle = UIModalPresentationCurrentContext;
    modal2VC.view.backgroundColor = [UIColor greenColor];
    [self presentModalViewController:modal2VC animated:YES];
    [modal2VC release];

    modal2VC.view.superview.bounds = CGRectMake(0, 0, 400, 400);
}

3 个答案:

答案 0 :(得分:4)

UIViewController *presentingViewController = //allocate your VC
[modalViewController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
UIViewController *modalViewController = //your modal VC
[presentingViewController presentModalViewController:modalViewController animated:YES];

这是您需要的所有代码;)

答案 1 :(得分:1)

听起来你的过渡是有效的,但翻转过渡中显示的白色背景是问题吗?

在翻转过渡期间,显示的白色背景实际上是window。您可以通过在backgroundColor中设置window的{​​{1}}属性来更改显示的颜色。

答案 2 :(得分:0)

这似乎是presentModalViewController:animated:的限制。

而不是[self presentModalViewController:modal2VC animated:YES],您可以使用UIView动画获得所需的效果。也许是这样的:

[UIView transitionWithView:self.view.window
                  duration:0.3
                   options:UIViewAnimationOptionTransitionFlipFromRight
                animations:^{
    [self presentModalViewController:modal2VC animated:NO];
} completion:NULL];