JakatX February 2016

present transparent modal view in iOS 9

there are lots of answers but none seems to be working normally/perfectly for iOS 9 specifically 9.2.. Someone help with it please. Its a simple scenario where:

1) Storyboard segues are connected to a single toBePresentedModally View Controller, i chose UIModalPresentationOverCurrentContext as well as switched and tried with UIModalPresentationCurrentContext when style from storyboard wasn't working.

2) i either get a black background after 1 second of happiness (it works fine for just a second) OR i get a blank controller when trying to present it through code by allocating a class of toBePresentedModally View Controller.

Any help would be appreciated!

Answers


Prabhu.Somasundaram February 2016

implement the class 'TransitionDelegate' which conforms to the protocol UIViewControllerTransitioningDelegate and give implementation for

- (id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {
    AnimatedTransitioning *controller = [[AnimatedTransitioning alloc]init];
    controller.isPresenting = YES;
    return controller;
}

Your AnimatedTransition class should look this,

#import "AnimatedTransitioning.h"
#import "MainViewController.h"
#import "SecondViewController.h"

@implementation AnimatedTransitioning

//===================================================================
// - UIViewControllerAnimatedTransitioning
//===================================================================

- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext {
    return 0.25f;
}

- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext {

    UIView *inView = [transitionContext containerView];
    SecondViewController *toVC = (SecondViewController *)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    MainViewController *fromVC = (MainViewController *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];

    [inView addSubview:toVC.view];

    CGRect screenRect = [[UIScreen mainScreen] bounds];
    [toVC.view setFrame:CGRectMake(0, screenRect.size.height, fromVC.view.frame.size.width, fromVC.view.frame.size.height)];

    [UIView animateWithDuration:0.25f
                     animations:^{

                         [toVC.view setFrame:CGRectMake(0, 0, fromVC.view.frame.size.width, fromVC.view.frame.size.height)];
                     }
                     completion:^(BOOL finished) {
                         [transit 


Umair Aamir February 2016

This is how, I have done in my code

let viewController = UIStoryboard.loadViewController("Identifier")
viewController.providesPresentationContextTransitionStyle = true
viewController.definesPresentationContext = true
viewController.modalPresentationStyle = .OverCurrentContext
self.presentViewController(viewController)

And it is working fine.


iOSEnthusiatic February 2016

If you want a transparent background for your ViewController try this!!

  • Take a View (named as DimmedView) and make it Equal width and Height to the superView.
  • Set SuperView's Background Color as ClearColor and DimmedView's LightGrayColor with alpha 0.5
  • Now take a CenterView with your actual content and set proper constraints.
  • Add Tap gesture to the DimmeedView if you want to dismiss Controller on touch outside of your CenterView.
  • Now when you present viewController set this property.

    ViewController *VC = segue.destinationViewController;
    VC.modalPresentationStyle = UIModalPresentationOverCurrentContext;
    
  • Don't forget to dissmiss ViewController on TapGesture Event.

enter image description here


JakatX March 2016

DashboardSettingsViewController *view=[self.storyboard   instantiateViewControllerWithIdentifier:@"dashboardSettings"];

view.providesPresentationContextTransitionStyle = YES;
view.definesPresentationContext = YES;
[view setModalPresentationStyle:UIModalPresentationOverCurrentContext];
CATransition *transition = [CATransition animation];
transition.duration = 0.5;
transition.timingFunction =
[CAMediaTimingFunction   functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;


//// for a smoother navigation
UIView *containerView = self.view.window;
[containerView.layer addAnimation:transition forKey:nil];
[self.navigationController presentViewController:view animated:YES completion:nil];

// lastly the background of to be presented view controller should be set to clear with alpha of your choice!

Post Status

Asked in February 2016
Viewed 1,225 times
Voted 14
Answered 4 times

Search




Leave an answer