ModalViewController Translucent Background - ios

I was using that piece of code to display a UIViewController as a modal with a translucent background (Working on IOS7 and lower).
MyViewController *myViewController = [[MyViewController alloc] init];
navController.modalPresentationStyle = UIModalPresentationCurrentContext;
[navController presentViewController:myViewController animated:NO completion:nil];
Now compiling with IOS8 show a modal with a black background.
Is there any solution ? (Without make an animated subView)
Thanks.

In iOS 8 and above, you can use 'UIModalPresentationOverCurrentContext' for this purpose. 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.
I was not aware that see-through modally presented view controllers were ever supported prior to iOS 8 (and will be looking into that for my own use), but the above option definitely works in my testing in the new OS.
Note: Be sure to give your presented view controller a backgroundColor of clearColor.

Related

Unable to set a dim background to a modal view

I'm developing an app targeting iOS 7 and above. I'd like to present modally a view with a dim background that partially shows the previous view below. I've read several posts dealing with this scenario, and I did:
Created a view controller scene in storyboard and set a modal segue to navigate to it.
Set the Presentation value of that modal segue to Current Context.
Set the view controller's view background color to clear color.
Added a full-screen view above the parent view, with black color background and 50% opacity.
Transition to the modal view is default and animated. While the animation, I see the view being presented as semi-transparent, but once the transition animation ends and view finally occupies the full screen, the view becomes opaque black.
What I'm doing wrong? How could I solve this?
As #luk2302 said, when you present a view controller modally, iOS removes the view controllers underneath it from the view hierarchy so is nothing underneath it except the app window, which is black. Anyway, iOS 7 has a new modal presentation style, UIModalPresentationCustom, that forces iOS not to remove the views underneath the presented view controller. But you must provide your own transition delegate to handle the presentation and dismiss animations
Check this link how to implement custom transition delegate.

Using Modal View Controllers and UIVisualEffectView

I'm trying to solve the problem described in this blog post: http://justabeech.com/2014/10/22/using-uivisualeffectview-in-a-modal-view-controller/
I have a UIViewController with a storyboard modal segue to another UIViewController of which the UIView has a background colour of [UIColor clearColor]and a UIVisualEffectView.
When I present the view controller, the visual effect is blurred until the transition is completed and then the background turns grey again (exactly as displayed in the gif on that blog post).
I set the Modal Transition Style to FullScreen as specified, but still the same problem remains. What else could I be missing to make this work?
EDIT: Also, I get the following error:
Warning: Attempt to present <ClocksDetailViewController: 0x7ff89cb5bc70> on <ClocksViewController: 0x7ff89c8afe90> whose view is not in the window hierarchy!
Thanks
You have probably used UIModalPresentationFullScreen instead of the correct UIModalPresentationOverFullScreen.
With the old UIModalPresentationFullScreen all the views under the presented controller are removed from the view hierarchy once the animation ends.
You need to set the modal presentation style of the UINavigationController, instead of the the UIViewController.
UINavigationController* navigationController = [[UIStoryboard storyboardWithName:#"myStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:#"myViewController"];
navigationController.modalPresentationStyle = UIModalPresentationOverFullScreen;

presentViewController with the tabbar

I have a app which has a tabbar which is presented in most of the ViewControllers. The problem is its not showing in an viewController which i'm presenting by this code.
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:songsViewController];
[self presentViewController:navigationController animated:YES completion:nil]
I'm using the presentViewController instead of the pushViewcontroller, cause i want to customize the navigationBar in this view.
How can i present my standard tabbar which i've created using storyboard?
When you use presentViewController:animated:completion, you are presenting the view controller modally, meaning it is not being contained within any of your existing containers like a UITabBarController or anything like that. So if you want something to show up when you present a UIViewController modally, it must be contained within the view controller that you're modally presenting. So from the looks of it, you're simply presenting a UINavigationController with your songsViewController contained within it. If you want to keep your UITabBar showing, either you need to add one to the view you're presenting, or you need to change your code so that you're not presenting a view controller modally here. And to add a second UITabBar for the modal view that matches the UITabBar that you were already presenting, it will make your app work rather strangely, so I would suggest trying to change it so you're not having to present a modal view at all.

UINavigationController containment, iOS7 and Status Bar. Bug?

I'm updating my custom "iAD Banner Controller" to support iOS 7.
It's basically an UIViewController container composed of 3 views:
the main view (the view of the contained controller)
the banner view
a status bar background view
When the AD is available, there is an animated transition that makes the banner view and the status bar background view appear sliding from the top.
This is all managed using autolayout, and should appear like this (the status bar background is the green one, and in this case it contains an UINavigationController):
The problem is this: Using UINavigationController as the contained controller, when the banner is not visible, the nav controller extends 20px under the status bar. This is ok and expected.
But, when I move it's superview (the container) down to let the iAD banner appear, the 20px extension remains there, with this result:
However, if I do something like rotating the interface, the nav controller detects that the status bar is "far", and then adjusts itself.
I tried to call setNeedsStatusBarAppearanceUpdate and layoutIfNeeded respectively on the controller and it's view, without results.
I attach the whole project if you want to have a look: Link to the project
By now I solved using a workaround: when the AD appear / disappear I call
[self.navigationController setNavigationBarHidden:YES animated:NO];
[self.navigationController setNavigationBarHidden:NO animated:NO];
using this workaround, I force UINavigationController to detect again that the status bar is "far" and It has to recalculate the offset.
Since my view hierarchy is not so simple, and I want to re-use my AD Controller in other projects, I used a Notification to alert that the AD was appearing/disappearing.
I'll wait for other better answer a few day before marking this as correct.
Thanks

Why Does presentModalViewController:animated: Turn The Background Black?

I am using presentModalViewController:animated: and while functionally it works correctly visually it has an artifact I want to remove. When the modally presented viewController appears its parent viewController is completely hidden with the background turning black. This is not what I want. My child viewController's view is translucent and I want to reveal the parent viewControllers view behind it. The effect I want is a piece of tracing paper sliding over the background.
I assumed presentModalViewController:animated: supported this. Is that not the case?
Thanks,
Doug
NavigationController and the View Controllers are designed in such a way that only one view controller may show at a time. When a new view controller is pushed/presented the previous view controller will be hidden by the system. So when you reduce the modal view's alpha you will possibly see the window's backgroundColor (the black color you see now).
If you want a translucent view to slide-in over the main view, you can add the view as the subView of main view and animate it using UIView Animations.
This may get you what you want:
presentingViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
presentingViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
doesn't work after ios7,you can fix it by after
presentingViewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
presentingViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
then both:
[appViews.rootViewController presentViewController:presentingViewController animated:YES completion:nil];

Resources