iOS View controller's view alpha - ios

Can I reveal the underlying view (or the view at the back of a view controller), by making a view controller's view transparent? I tried and it just fades to black and doesn't reveal anything behind it.
Reason?
EDIT:
Okay, this question needs more context.
I have a view controller. Now I am going to present another view controller(simple presentation of view controller, modally). After the new view controller has been presented, I am making its view transparent with alpha=0. Why does it not reveal the underlying view controller's view?
Will using the iOS 7 Transition API help?

If you present your view controller modally (using presentViewController:animated:completion:) then the presenting view controller's view will be removed removed from the window, therefore you cannot see through your presented view controller to the presenting view controller. You might want to use child view controller: https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomContainerViewControllers/CreatingCustomContainerViewControllers.html
Alternatively, you can present your view controller inside a new UIWindow.

You cannot see the original view controller because you use -presentViewController:animated:completion: which will hide the presenting view controller after the animation finished.
You can set the modalPresentationStyle to one of UIModalPresentationOverCurrentContext, UIModalPresentationOverFullScreen and UIModalPresentationCustom before you called 'presentViewController:animated:completion' so that the underlying presenting view controller will not be hidden.

If you would like to have the same background image showing below all UIViewController you can add a UIImageView to the [UIApplication sharedApplication].window in the applicationdidfinishlaunching method

Related

Loading View Controller from another View Controller inside Container View

I'm developing an app for iOS.
I want to have a view controller (called child) that appears inside another view in my main view controller (called parent).
I managed to do this by adding a container view which embeds the child view controller successfully.
In my child view controller I have a button that opens another (3rd) view controller.
I want this screen to open within the bounds of the view container - but it opens on a full screen.
Is there a way I can define the view container in a way that all segues inside of it will show inside its bounds?
definesPresentationContext - a UIViewController's property that might be helpful here.
A Boolean value that indicates whether this view controller's view is covered when the view controller or one of its descendants presents a view controller.
https://developer.apple.com/reference/uikit/uiviewcontroller/1621456-definespresentationcontext
Set the child's property to true:
childViewController.definesPresentationContext = true
Also, before presenting the viewController (3rd), set its modal presentation style:
viewControllerToBePresented.modalPresentationStyle = .overCurrentContext
Hope this helps!
Try this post. It might help for adding viewcontrollers within bounds.
http://khanlou.com/2015/04/view-controllers-in-cells/

How to present a View Controller without hiding the tabBar

I have a UITabBarController with five view controllers in it. In one view controller, a button can be pressed to present a new ViewController, but the tabbar is covered. How can I present the controller and keep the tabbar visible?
When you present something, it will cover entire screen.
The controller from where you want to present a new controller, make it as navigation controller rather keeping it as simple controller.
So, you can push the new controller on it rather than you present.
[<presentingViewControllerInstance> setModalPresentationStyle:UIModalPresentationOverCurrentContext];
Use currentContext as presentation style for the presenting view controller before presenting. No need to create a navigation controller and push.

View Controller Transparent Background

How can I create a view controller with a transparent background that overlays another view controller where the bottom view controller is still visible in iOS 9? The way that works in iOS 8 no longer works.
First you can set overlaid view controller's background colour as clear colour.
You can use presentViewController method to overlay new view controller.
This from apple docs
When presenting a view controller using the UIModalPresentationFullScreen style, UIKit normally removes the views of the underlying view controller after the transition animations finish. You can prevent the removal of those views by specifying the UIModalPresentationOverFullScreen style instead.
So you can set overlaid view controller's modalPresentationStyle to UIModalPresentationOverFullScreen
I also hope this may be help
When using one of the full-screen presentation styles, the view controller that initiates the presentation must itself cover the entire screen. If the presenting view controller does not cover the screen, UIKit walks up the view controller hierarchy until it finds one that does. If it can’t find an intermediate view controller that fills the screen, UIKit uses the root view controller of the window.
To solve this problem you just have to change the Alpha information of your View. To get this view on top of others, change the Transition Style of the ViewController.
FYI: The syntax is now:
childVC.modalPresentationStyle = UIModalPresentationStyle.OverFullScreen

UISplitViewController and Modal view controller presentation issues

I am having troubles with an application where I have a split view controller and would like to display a modal view controller over the top.
To test this, I have created a basic project which mimics the structure of my application. I have uploaded this to Github for anyone to download: https://github.com/CaptainRedmuff/SplitViewDemo
There are two main issues which I will detail below:
Issue 1:
When presenting the modal view controller in portrait orientation with the master view controller visible (as a popover I believe), the modal view controller is displayed underneath the master view controller. Any attempts to interact with the model view controller cause the app to crash.
Issue 2:
When presenting the modal view controller from the tab bar controller (in the master view controller), the modal view controller is automatically dismissed when the device is rotated to landscape orientation as the master view controller is removed from the hierarchy.
One possible fix I have found is to conform to the UISplitViewControllerDelegate method - (BOOL)splitViewController:shouldHideViewController:inOrientation: and return NO to force the master view controller to always be visible. This is not the behaviour that I want however so this is not a viable fix.
Considering that there is no way to programatically display or dismiss the master view controller, I am at a loss for alternative methods to present a view controller modally over the top of the entire split view controller.
Before presenting modal VC you must dismiss popover like:
[self.popover dismissPopoverAnimated:NO];
The issue occurred probably because UIPopoverController is added to the window instead of UISplitViewController.

Presenting/dismissing modal view controller with custom animations does not display presenting view controller underneath

I have implemented a view controller which provides a navigation structure similar to UINavigationController. It is using view controller containment. All view controllers are added as children.
When I present a modal view controller from a view controller within this navigational flow, the underlying view disappears during the custom transition and the user is left viewing the Window view below.
[UIView animateWithDuration:0.35 animations:^{
self.view.transform = CGAffineTransformMakeScale(0.4, 0.4);
self.view.alpha = 0.0;
} completion:^(BOOL finished) {
[[self presentingViewController] dismissViewControllerAnimated:NO completion:nil];
}];
This is a very jarring experience. Previously this animation would shrink the modal view controller's view and fade it into the presenting view controller's view underneath. As I stated before, now the user is exposed to the view of the Window (which currently has not had an color values set).
Refering to the View Controller documentation I feel as though I have set all the right fields, however, something is incorrect.
A view controller presents another view controller when it wants that
view controller to perform a task. The presenting view controller is
in charge of this behavior. It configures the presented view
controller, receives information from it, and eventually dismisses it.
However, while it is being presented, the presented view controller’s
view is temporarily added to the window’s view hierarchy.
My presenting view controller is my custom navigation controller, the presented view controller is a modal view controller that allows the user to compose a conversation. My application's window root view controller is correctly configured to my custom navigation controller.
I also read some more about presentation context and have configured my custom navigation controller as having definesPresentationContext as YES.
When a view controller is presented, the portion of the screen that it
covers is defined by a presentation context provided to it by another
view controller. The view controller that provides the presentation
context does not need be the same view controller that presented it.
Figure 1-15 shows the same view controller hierarchy that is presented
in Figure 1-14. You can see that the content view presented the view
controller, but it did not provide the presentation context. Instead,
the view controller was presented by the tab controller. Because of
this, even though the presenting view controller only covers the
portion of the screen provided to it by the tab view controller, the
presented view controller uses the entire area owned by the tab view
controller. Within my custom navigation controller I have not
overriden any methods related to presentation or dismissal of view
controllers. All of the child view controllers that are added are all
added as childViewControllers and their views have been added to this
custom navigation controller.
Why would a custom transition show the Window's view instead of
respecting the custom containment view controller which provides the
presentation context?
Why would the traditional transition animations work as expected?

Resources