Using Modal View Controllers and UIVisualEffectView - ios

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;

Related

ModalViewController Translucent Background

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.

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.

Presenting a View controller only in the DetailViewController of UISplitViewController

I am working with UISplitViewController, and I want to present a VC from the detail view controller of the splitViewController. I do it like this:
[self presentModalViewController:VC animated:YES];
also tried this from master VC.
[self.detailVC presentModalViewController:VC animated:YES];
It comes for the full screen I mean it is like presenting from the UISplitViewController itself. I tried changing the modal presentation styles even though I got the same results.
What I want is the VC that is presented should be presented within the bounds of the DetailVC and it can be of DetailVC's entire frame, but not come anywhere near to the MasterVC.
For now I am using UIView Animation to achieve this, any ideas on how to do this just by presenting?
As of Xcode 6:
In the storyboard, select the present modally segue, and go to the Identity Inspector, and choose Current Context for the Presentation option.
Your detail view controller should be inside a navigation controller, then you push your additional view controller into the navigation controller instead of modally.

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];

TableViewCell disappears when push UINavigationController in UITabBarController's More tableview

I add 6 navigation controllers to UITabBarController's viewControllers. As normal, a More tab is created to list the last two. The problem is: after I select a table cell in the More table view, that cell's content fade out and disappear before the view controller push in. And then, after I back to the More table view by click the Back button, that cell's content show again. I guess the reason is More table view in its own navigation controller, and it push another navigation controller (created by me). I don't want to remove my navigation controller because I want to allow user rearrange tabs using the UITabBarController's Edit function. Can anyone suggest what I should do?
Create instances of your 6 navigation controllers in AppDelegate and retain them. And release in dealloc method
Just had the same problem. In my case I accidentally assigned the tabBarItem to the VC inside the navigation controller. When I instead initialized the tabBarItem on the navigation controller, the flickering / disappearing stopped.
MyViewController* viewController = [[MyViewController alloc] init];
UINavigationController* navigation = [[UINavigationController alloc] initWithRootViewController:viewController];
[viewController release];
// this has to be navigation.tabBarItem (not viewController.tabBarItem)
[navigation.tabBarItem initWithTitle:#"Title" image:[UIImage imageNamed:#"fancy.png"]
tag:42];
Initializing the tabBarItem on the viewController still showed the icon which made it harder to discover. I'm also not very sure (actually I think it's bad) about the way I initialize the tabBarItem (without alloc). But I had troubles with disappearing icons etc and hey, it works ;-)

Resources