Este código funciona bien en iPhone con iOS6 e iOS7:
presentedVC.view.backgroundColor = YOUR_COLOR; // can be with 'alpha'
presentingVC.modalPresentationStyle = UIModalPresentationCurrentContext;
[presentingVC presentViewController:presentedVC animated:YES completion:NULL];
En este caso, se pierde la animación deslizante. Para conservar la animación, aún puede usar la siguiente extensión "no elegante":
[presentingVC presentViewController:presentedVC animated:YES completion:^{
[presentedVC dismissViewControllerAnimated:NO completion:^{
presentingVC.modalPresentationStyle = UIModalPresentationCurrentContext;
[presentingVC presentViewController:presentedVC animated:NO completion:NULL];
}];
}];
Si nuestro presentador V está ubicado dentro de UINavigationController o UITabbarController, debe operar con esos controladores como presentando VC.
Además, en iOS7 puede implementar un UIViewControllerTransitioningDelegate
protocolo de aplicación de animación de transición personalizada . Por supuesto, en este caso puedes obtener un fondo transparente
@interface ModalViewController : UIViewController <UIViewControllerTransitioningDelegate>
Primero, antes de presentar debes configurar modalPresentationStyle
modalViewController.modalPresentationStyle = UIModalPresentationCustom;
Entonces tienes que implementar dos métodos de protocolo
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source
{
CustomAnimatedTransitioning *transitioning = [CustomAnimatedTransitioning new];
transitioning.presenting = YES;
return transitioning;
}
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed
{
CustomAnimatedTransitioning * transitioning = [CustomAnimatedTransitioning new];
transitioning.presenting = NO;
return transitioning;
}
Lo último es definir tu transición personalizada en CustomAnimatedTransitioning
clase
@interface CustomAnimatedTransitioning : NSObject <UIViewControllerAnimatedTransitioning>
@property (nonatomic) BOOL presenting;
@end
@implementation CurrentContextTransitionAnimator
- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext
{
return 0.25;
}
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext
{
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
if (self.presenting) {
// custom presenting animation
}
else {
// custom dismissing animation
}
}