Presenting a modal ViewController which has semi transparent background - ios

I'm presenting a SecondViewController modally on FirstViewController and the SecondViewController has a semi transparent background (White color with 70 percent opacity).
The problem I'm facing is when I present SecondViewController, the view of FirstViewController remains visible until the SecondViewController has finished presenting.
This makes the UI look laggy. The behaviour I'm expecting is as soon as the SecondViewController is presented, the view for FirstViewController should be invisible, or gradually faded out before the view of SecondViewController appears.
Any help will be greatly appreciated!
The code I use for presenting is :
SecondViewController *cntrlr = (SecondViewController *)[[UIStoryboard activationStoryboard] instantiateViewControllerWithIdentifier:#“UserVC”];
[cntrlr setModalPresentationStyle:UIModalPresentationPopover];
[self presentViewController:cntrlr animated:YES completion:nil];

After iOS 3.2 there is a method to do this without any “tricks” – see the documentation for the modalPresentationStyle property. You have a rootViewController which will present the viewController. So here's the code to success:
viewController.view.backgroundColor = [UIColor clearColor];
rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[rootViewController presentModalViewController:viewController animated:YES];
With this method the viewController's background will be transparent and the underlying rootViewController will be visible.

SecondViewController *cntrlr = (SecondViewController *)[[UIStoryboard activationStoryboard] instantiateViewControllerWithIdentifier:#“UserVC”];
[cntrlr setModalPresentationStyle:UIModalPresentationPopover];
self.view.alpha = 0.0f;
[self.navigationController.navigationBar setHidden:YES];
[self presentViewController:cntrlr animated:YES completion:nil];
// Need to set FirstViewController alpha 1.0f after dismisViewController
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.view.alpha = 1.0f;
[self.navigationController.navigationBar setHidden:NO];
}

Related

Present a blurred UIViewController on top of another UIViewController

I have 2 VCs - firstVC and secondVC.
secondVC's view's color is clear color and it has a UIVisualEffect view with dark blur.
I want to present secondVC modally on firstVC but when I do that, firstVC becomes black.
Thank you
You need to set the modalPresentationStyle appropriately on the presented (secondVC) controller.
UIModalPresentationOverFullScreen or UIModalPresentationOverCurrentContext will provide the effect of the second VC's content over the top of the first VC.
if ios version >= 8.0 then
SecondViewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:SecondViewController animated:YES completion:nil];
if using ios7 & navigation controller then
self.navigationController.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:SecondViewController animated:YES completion:nil];
if there is no navigation controller then
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:SecondViewController animated:YES completion:nil];

UINavigationController clear background color

That simple example but that don't work;
I have ViewController where inside on NavigationConroller, then I want to add new ViewConroller with its self navigation controller.
In main viewController:
CustomViewController *vc = [[CustomViewController alloc] init];
NewNavigationVC *nav = [[NewNavigationVC alloc] initWithRootViewController:vc];
[self presentViewController:nav animated:NO completion:nil];
Two controllers has a background color clear, but still black color.
Navigation bar I can do clear, but not a view.
UPDATE:
if i change self.window.backroundColor to red for example, that work but not clear
UPDATE 2:
[self addChildViewController:vc];
[self.view addSubview:vc.view];
[vc didMoveToParentViewController:self];
and when I want to dealloc vc
[vc willMoveToParentViewController:nil];
[vc.view removeFromSuperview];
[vc removeFromParentViewController];
All work ok without navigation controller
A viewController's view's backgroundColor can't be clear (as in showing the previous viewController's view on the stack). Pushing or presenting a viewController will put the new viewController on the stack and hide the previous viewController completely.
If you want a clear backgroundColor on the view, you will need to either:
1) set the viewController as a childViewController of the previous viewController - then animate the transition yourself.
Or
2) transplant the viewController logic into the previous viewController and have a new uiview act as that view (you also need to animated the transition yourself).
The solution is as follows. For clear example we use tableViewController:
UITableViewController *modalVC = [UITableViewController new];
UINavigationController *modalNVC = [[UINavigationController alloc] initWithRootViewController:modalVC];
UIViewController *mainVC = [UIViewController new];
UINavigationController *mainNVC = [[UINavigationController alloc] initWithRootViewController:mainVC];
modalVC.view.backgroundColor = UIColor.clearColor;
mainVC.view.backgroundColor = UIColor.redColor;
mainNVC.modalPresentationStyle = UIModalPresentationCurrentContext;
[mainNVC presentViewController:modalNVC animated:YES completion:NULL];
The key feature is that you have to set modalPresentationStyle of presentingViewController to UIModalPresentationCurrentContext.
It works fine BUT without slide animation. You will get result immediately.
But you can still use "blood hack" to retain visual animation by successive presenting, dismissing and presenting again:
modalVC.view.backgroundColor = UIColor.clearColor;
mainVC.view.backgroundColor = UIColor.redColor;
[mainNVC presentViewController:modalNVC animated:YES completion:^{
[modalNVC dismissViewControllerAnimated:NO completion:^{
mainNVC.modalPresentationStyle = UIModalPresentationCurrentContext;
[mainNVC presentViewController:modalNVC animated:NO completion:NULL];
}];
}];
You basically need to tell the navigation controller to:
navigation.modalPresentationStyle = .overCurrentContext
In other words:
A presentation style where the content is displayed over another view controller’s content.
and that's it.
You can also make sure that:
navigation.view.backgroundColor = .clear

UIModalPresentationCurrentContext not showing transparent background

I have UIViewController called TestVC who's background is set to clearColor:
#implementation TestVC
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
}
#end
I present the TestVC from another view controller via:
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:[[TestVC alloc] init] animated:YES completion:NULL];
But the present TestVC is white and it obscures the screen. Is there a way to have it transparent or partially obscure the underlying view controller?
Thanks
Try setting the modalPresentationStyle on the TestVC, not the view controller that is doing the presenting.
And if UIModalPresentationCurrentContext still doesn't work, try UIModalPresentationCustom.
sorry .. my fault... just like the comment bellow, you have to set the view controller that you're going to present.
Add this line to the controller where you present the TestVC
TestVCClass *TestVC =[[TestVCClass alloc]init]; TestVC.modalPresentationStyle = UIModalPresentationOverCurrentContext; [self presentViewController:TestVC animated:YES completion:nil];

iOS: Modal ViewController with transparent background

I'm trying to present a view controller modally, with a transparent background. My goal is to let both the presenting and presented view controllers's view to be displayed at the same time. The problem is, when the presenting animation finishes, the presenting view controller's view disappears.
- (IBAction)pushModalViewControllerButtonPressed:(id)sender
{
ModalViewController *modalVC = [[ModalViewController alloc] init];
[self presentViewController:modalVC animated:YES completion:nil];
}
I know I could just add the view as a subview, but I'd like to avoid this solution for some reason. How could I fix it?
For those trying to get this to work in iOS 8, the "Apple-approved" way to display a transparent modal view controller is by setting modalPresentationStyle on the presented controller to UIModalPresentationOverCurrentContext.
This can be done in code, or by setting the properties of the segue in the storyboard.
From the UIViewController documentation:
UIModalPresentationOverCurrentContext
A presentation style where the content is displayed over only the
parent view controller’s content. The views beneath the presented
content are not removed from the view hierarchy when the presentation
finishes. So if the presented view controller does not fill the screen
with opaque content, the underlying content shows through.
When presenting a view controller in a popover, this presentation
style is supported only if the transition style is
UIModalTransitionStyleCoverVertical. Attempting to use a different
transition style triggers an exception. However, you may use other
transition styles (except the partial curl transition) if the parent
view controller is not in a popover.
Available in iOS 8.0 and later.
https://developer.apple.com/documentation/uikit/uiviewcontroller
The 'View Controller Advancements in iOS 8' video from WWDC 2014 goes into this in some detail.
Note:
Be sure to give your presented view controller a clear background color, lest it not actually be see-through!
You have to set this before presenting ie setting this parameter in the viewDidLoad of the presentedViewController won't have any affect
In iOS 8.0 and above it can be done by setting the property modalPresentationStyle to UIModalPresentationOverCurrentContext
//Set property **definesPresentationContext** YES to avoid presenting over presenting-viewController's navigation bar
self.definesPresentationContext = YES; //self is presenting view controller
presentedController.view.backgroundColor = [YOUR_COLOR with alpha OR clearColor]
presentedController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:presentedController animated:YES completion:nil];
This following code only works on the iPad.
self.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentModalViewController:modalVC animated:YES];
I would go with adding a sub view.
Here is a very good discussion. Look at the comments specifically. Not only the answer.
Modal View
If I were you I wouldn't do it. I would add a sub view and do it. It seems to give me a better control over things.
EDIT:
As mentioned by Paul Linsay, since iOS 8 all that's needed is UIModalPresentationOverFullScreen for the modalPresentationStyle of the ViewController being presented. This would also cover of navigationBar and tabBar buttons.
This code works fine on iPhone under iOS6 and iOS7:
presentedVC.view.backgroundColor = YOUR_COLOR; // can be with 'alpha'
presentingVC.modalPresentationStyle = UIModalPresentationCurrentContext;
[presentingVC presentViewController:presentedVC animated:YES completion:NULL];
In this case you miss slide-on animation. To retain animation you still can use the following "non-elegant" extension:
[presentingVC presentViewController:presentedVC animated:YES completion:^{
[presentedVC dismissViewControllerAnimated:NO completion:^{
presentingVC.modalPresentationStyle = UIModalPresentationCurrentContext;
[presentingVC presentViewController:presentedVC animated:NO completion:NULL];
}];
}];
If our presentingV is located inside of UINavigationController or UITabbarController you need to operate with that controllers as presentingVC.
Further, in iOS7 you can implement custom transition animation applying UIViewControllerTransitioningDelegate protocol. Of course, in this case you can get transparent background
#interface ModalViewController : UIViewController <UIViewControllerTransitioningDelegate>
First, before presenting you have to set modalPresentationStyle
modalViewController.modalPresentationStyle = UIModalPresentationCustom;
Then you have to implement two protocol methods
- (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;
}
The last thing is to define your custom transition in CustomAnimatedTransitioning class
#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
}
}
I struggled a bit with the Interface Builder of XCode 7 to set the Presentation Style as #VenuGopalTewari suggested. In this version, there seems to be no Over Current Context or Over Full Screen presentation mode for the segue. Thus, to make it work, I set the mode to Default:
with
Additionally I set the presentation mode of the modally presented view controller to Over Full Screen:
Create a segue to present modally and set Presentation property of that segue to over current context
it will work 100 %
The solution to this answer using swift would be as follows.
let vc = MyViewController()
vc.view.backgroundColor = UIColor.clear // or whatever color.
vc.modalPresentationStyle = .overCurrentContext
present(vc, animated: true, completion: nil)
PresentViewController with Transparent background - in iOS 8 and iOS 9
MYViewController *myVC = [self.storyboard instantiateViewControllerWithIdentifier:#"MYViewController"];
myVC.providesPresentationContextTransitionStyle = YES;
myVC.definesPresentationContext = YES;
[myVC setModalPresentationStyle:UIModalPresentationOverCurrentContext];
[self.navigationController presentViewController:myVC animated:YES completion:nil];
And in MYViewController set background color black and reduce opacity
It's a bit of hacky way, but for me this code works (iOS 6):
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[self presentViewController:self.signInViewController animated:YES completion:^{
[self.signInViewController dismissViewControllerAnimated:NO completion:^{
appDelegate.window.rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:self.signInViewController animated:NO completion:nil];
appDelegate.window.rootViewController.modalPresentationStyle = UIModalPresentationFullScreen;
}];
}];
This code works also on iPhone
This category worked for me (ios 7, 8 and 9)
H file
#interface UIViewController (navigation)
- (void) presentTransparentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion;
#end
M file
#implementation UIViewController (navigation)
- (void)presentTransparentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion
{
if(SYSTEM_VERSION_LESS_THAN(#"8.0")) {
[self presentIOS7TransparentController:viewControllerToPresent withCompletion:completion];
}else{
viewControllerToPresent.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:viewControllerToPresent animated:YES completion:completion];
}
}
-(void)presentIOS7TransparentController:(UIViewController *)viewControllerToPresent withCompletion:(void(^)(void))completion
{
UIViewController *presentingVC = self;
UIViewController *root = self;
while (root.parentViewController) {
root = root.parentViewController;
}
UIModalPresentationStyle orginalStyle = root.modalPresentationStyle;
root.modalPresentationStyle = UIModalPresentationCurrentContext;
[presentingVC presentViewController:viewControllerToPresent animated:YES completion:^{
root.modalPresentationStyle = orginalStyle;
}];
}
#end
If you're using Storyboard, you can follow this step:
Add a view controller (V2), setup the UI the way you want it
add an UIView - set background to black and opacity to 0.5
add another UIView(2) - that will serve as your popup (Pls take note that the UIView and the UIView(2) must have the same level/hierarchy. Dont make the imageview the child of the view otherwise the opacity of the uiview will affect the UIView(2))
Present V2 Modally
Click the segue. In the Attributes inspector, Set Presentation as Over Full Screen. Remove animation if you like
Select V2. In the Attributes inspector, Set Presentation as Over Full Screen. Check Defines Context and Provides Context
Select the MainView of your V2 (Pls. Check image). Set backgroundColor to Clear Color
I added these three lines in the init method in the presented view controller, and works like a charm:
self.providesPresentationContextTransitionStyle = YES;
self.definesPresentationContext = YES;
[self setModalPresentationStyle:UIModalPresentationOverCurrentContext];
EDIT (working on iOS 9.3):
self.modalPresentationStyle = UIModalPresentationOverFullScreen;
As per documentation:
UIModalPresentationOverFullScreen
A view presentation style in which the presented view covers the screen. The views beneath the presented content are not removed from the view hierarchy when the presentation finishes. So if the presented view controller does not fill the screen with opaque content, the underlying content shows through.
Available in iOS 8.0 and later.
Alternate way is to use a "container view". Just make alpha below 1 and embed with seque. XCode 5, target iOS7. Tested on iPhone.
Container view available from iOS6.
Link to blog post about that.
I have created an object to handle the presentation of what I call a "superposed modal", meaning it retains the background's view and allows you to have a modal with a transparent background.
It has a single, simple method that does this:
- (void)presentViewController:(UIViewController *)presentedViewController
fromViewController:(UIViewController *)presentingViewController
{
presentedViewController.modalPresentationStyle = UIModalPresentationCustom;
presentedViewController.transitioningDelegate = self;
presentedViewController.modalPresentationCapturesStatusBarAppearance = YES;
[presentedViewController setNeedsStatusBarAppearanceUpdate];
[presentingViewController presentViewController:presentedViewController
animated:YES
completion:nil];
}
It's important to set the modalPresentationCapturesStatusBarAppearance property to YES and force the status bar appearance to update, if your presented view controller has a different preferredStatusBarStyle.
This object should have a #property (assign, nonatommic) isPresenting
You want this object to comply to the UIViewControllerAnimatedTransitioning and UIViewControllerTransitioningDelegate protocols and implement the following methods:
- (id)animationControllerForPresentedController:(UIViewController *)presented
presentingController:(UIViewController *)presenting
sourceController:(UIViewController *)source
{
self.isPresenting = YES;
return self;
}
- (id)animationControllerForDismissedController:(UIViewController *)dismissed
{
self.isPresenting = NO;
return self;
}
and:
- (NSTimeInterval)transitionDuration:(id)transitionContext
{
return 0.25;
}
- (void)animateTransition:(id)transitionContext
{
UIViewController* firstVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController* secondVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIView* containerView = [transitionContext containerView];
UIView* firstView = firstVC.view;
UIView* secondView = secondVC.view;
if (self.isPresenting) {
[containerView addSubview:secondView];
secondView.frame = (CGRect){
containerView.frame.origin.x,
containerView.frame.origin.y + containerView.frame.size.height,
containerView.frame.size
};
firstView.tintAdjustmentMode = UIViewTintAdjustmentModeDimmed;
[UIView animateWithDuration:0.25 animations:^{
secondView.frame = containerView.frame;
} completion:^(BOOL finished) {
[transitionContext completeTransition:YES];
}];
} else {
[UIView animateWithDuration:0.25 animations:^{
firstView.frame = (CGRect){
containerView.frame.origin.x,
containerView.frame.origin.y + containerView.frame.size.height,
containerView.frame.size
};
} completion:^(BOOL finished) {
[transitionContext completeTransition:YES];
}];
}
}
This does a slide-in-from-the-bottom animation mimicking the default modal animation, but you can make it whatever you want.
The important thing is that the presenting view controller's view will remain in the back, letting you create a transparent effect.
This solution works for iOS 7+
A very simple way of doing this (using Storyboards, for example) is:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"SomeStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"SomeStoryboardViewController"];
// the key for what you're looking to do:
vc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
vc.view.alpha = 0.50f;
[self presentViewController:vc animated:YES completion:^{
// great success
}];
This will present a UIViewController in a Storyboard modally, but with a translucent background.
Working for iOS 7-10
if #available(iOS 8.0, *) {
nextVC.modalPresentationStyle = .OverCurrentContext
self.presentViewController(nextVC, animated: true, completion: nil)
} else {
// Fallback on earlier version
self.modalPresentationStyle = .Custom
nextVC.modalTransitionStyle = .CrossDissolve
self.presentViewController(nextVC, animated: false, completion: nil)
}
}
To recap all the good answers and comments here and to still have an animation while moving to your new ViewController this is what I did: (Supports iOS 6 and up)
If your using a UINavigationController \ UITabBarController this is the way to go:
SomeViewController *vcThatWillBeDisplayed = [self.storyboard instantiateViewControllerWithIdentifier:#"SomeVC"];
vcThatWillBeDisplayed.view.backgroundColor = [UIColor colorWithRed: 255/255.0 green:255/255.0 blue:255/255.0 alpha:0.50];
self.navigationController.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:presentedVC animated:YES completion:NULL];
If you'll do that you will lose your modalTransitionStyle animation. In order to solve it you can easily add to your SomeViewController class this:
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[UIView animateWithDuration:0.4 animations:^() {self.view.alpha = 1;}
completion:^(BOOL finished){}];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.alpha = 0;
}
Of course you should set UIModalPresentationCurrentContext, but the place to set clearColor is very important too! You can't set background in viewDidLoad function, set it before the view did load like in the root view controller or in the init function of the controller that going to present!
actionController.view.backgroundColor = [UIColor clearColor];
[self presentViewController:actionController animated:YES completion:nil];
or
- (instancetype)init {
self = [super initWithNibName:nil bundle:nil];
if(self) {
self.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self.view setBackgroundColor:[UIColor clearColor]];
}
return self;
}
Swift 4.2
guard let someVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "someVC") as? someVC else {
return
}
someVC.modalPresentationStyle = .overCurrentContext
present(someVC, animated: true, completion: nil)
If you are using modal segue, make sure to set it as this image (you can turn off animation if you want)
A complete method tested on iOS 7 and iOS 8.
#interface UIViewController (MBOverCurrentContextModalPresenting)
/// #warning Some method of viewControllerToPresent will called twice before iOS 8, e.g. viewWillAppear:.
- (void)MBOverCurrentContextPresentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion;
#end
#implementation UIViewController (MBOverCurrentContextModalPresenting)
- (void)MBOverCurrentContextPresentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion {
UIViewController *presentingVC = self;
// iOS 8 before
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1) {
UIViewController *root = presentingVC;
while (root.parentViewController) {
root = root.parentViewController;
}
[presentingVC presentViewController:viewControllerToPresent animated:YES completion:^{
[viewControllerToPresent dismissViewControllerAnimated:NO completion:^{
UIModalPresentationStyle orginalStyle = root.modalPresentationStyle;
if (orginalStyle != UIModalPresentationCurrentContext) {
root.modalPresentationStyle = UIModalPresentationCurrentContext;
}
[presentingVC presentViewController:viewControllerToPresent animated:NO completion:completion];
if (orginalStyle != UIModalPresentationCurrentContext) {
root.modalPresentationStyle = orginalStyle;
}
}];
}];
return;
}
UIModalPresentationStyle orginalStyle = viewControllerToPresent.modalPresentationStyle;
if (orginalStyle != UIModalPresentationOverCurrentContext) {
viewControllerToPresent.modalPresentationStyle = UIModalPresentationOverCurrentContext;
}
[presentingVC presentViewController:viewControllerToPresent animated:YES completion:completion];
if (orginalStyle != UIModalPresentationOverCurrentContext) {
viewControllerToPresent.modalPresentationStyle = orginalStyle;
}
}
#end
in appdelegate :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[_window rootViewController]setModalPresentationStyle:UIModalPresentationCurrentContext];
return YES;
}
in you first view controller from where you have to load next view:
NextViewController *customvc = [[NextViewController alloc]init];
[self presentViewController:customvc animated:YES completion:^{
}];
in your nextViewController which is to be added transparent:
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
UIView* backView = [[UIView alloc] initWithFrame:self.view.frame];
backView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
[self.view insertSubview:backView atIndex:0];
}
The Login screen is a modal, meaning that it sits on top of the previous screen. So far we have Blurred Background, but it’s not blurring anything; it’s just a grey background.
We need to set our Modal properly.
image link target
First, we need to change the View Controller’s View background to Clear color. It simply means that it should be transparent. By default, that View is white.
Second, we need to select the Segue that leads to the Login screen, and in the Attribute Inspector, set the Presentation to Over Current Context. This option is only available with Auto Layout and Size Classes enabled.
image link target
Set navigation's modalPresentationStyle to UIModalPresentationCustom
and set your presented view controller's background color as clear color.

iOS - presentViewController with transparency

I would like to present a view controller full screen semi-transparently so that I still see the view underneath it. The following code presents the new view controller, but it replaces the current one. What is the best way to keep the original view controller visible? The view of the new view controller will have a semi-transparent black background.
NewViewController* newVC = [[NSClassFromString(#"NewViewController") alloc] initWithNibName:deviceNib bundle:nil];
newVC.modalPresentationStyle = UIModalPresentationFullScreen;
newVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:newVC animated:YES completion:NULL];
Present a semi-transparent View, not a view controller.
mySemiTransparentView.alpha = 0.0f;
[self.view addSubview:mySemiTransparentView];
mySemiTransparentView is your full-screen view. You can animate it into place:
[UIView beginAnimations:#"fadeIn" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:0.4f];
mySemiTransparentView.alpha = 0.5f;
[UIView commitAnimations];
You can present semi-transparent modal controller in the following way:
NewViewController* newVC = [[NSClassFromString(#"NewViewController") alloc] initWithNibName:deviceNib bundle:nil];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
newVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:newVC animated:YES completion:NULL];
Notice here that you have to set the constant UIModalPresentationCurrentContext to self.modalPresentationStyle, not to newVC.modalPresentationStyle
Furthermore, when you use UIModalTransitionStyleCrossDissolve the alpha of the newVC.view will be overridden during the transition, so if you want semi-transparent background you'll need to keep newVC.view's backgroundColor clear and just add another UIView as it's subview with semi-transparent backgroundColor

Resources