UIVisualEffectView turning gray (not working) - ios

My app has an interface that is set up so that when I click a button, a view controller will be presented modally. In that view controller, there is nothing but a UIVisualEffectView. When I run my app, it works but then after a second the UIVisualEffectView turns gray. Why is it doing that?
Here is a link to a GIF showing my problem:
click here to view gif

The problem is with the way you present your UIVisualEffectView over the background view. Since you are using some sort of full-screen presentation the underlying view is stopped being updated in order to save resources.
You should be able to get this to work by adjusting the presentation style, such as:
myEffectView.modalPresentationStyle = .overCurrentContext
Edit
Since you said in a comment that you're using Interface Builder, you can also adjust this there by selecting your UIViewController that contains the UIVisualEffectView and adjusting its properties:

Related

xcode and iPhone simulations show weird top grey bar behind views after navigation, how to remove them?

I am trying to update an old Storyboard and viewControllers. in Interface Builder, my viewControllers has the following grey bar that I do not know how and why they are appearing, they were not there previously:
These are also visible when I try to simulate my apps in the iPhone simulator as follow:
When I start my app, the views are stretched with a tiny view of this space as follow:
However, when I start navigating to other viewControllers the space is visible as shown in the previous screenshot.
Any idea of how to stretch my views all the way to cover these areas?
I am currently using swift. The navigation is being done using Storyboard Segue.
Thank you.
This is just the storyboard showing the way the screen will be presented, that grey bar represents the view that will be behind that view controller. This kind of presentation is called modal (page sheet or form sheet) the two have different effects on iPad
Code Fix
To fix this, change the modalPresentationStyle to overCurrentContext on the view controller you're going to present. So in code do viewControllerToPresent.modalPresentationStyle = .overCurrentContext
Storyboard Fix
in storyboard select the segue (the line linking the two screens) and then on the far right menu select the item 3rd in from the right, you should see a section called presentation, change it to Current Context.

Visual Effects View with blur turns dark gray

Currently we have a Visual Effects View that was added in storyboard like so:
The view is presented modally but for some strange reason I can see the image underneath blurred during the transition but when the transition is complete the blur turns a dark gray:
No code has been written yet, I'm trying to do this all in storyboard.
You need to set the presentation style of your second view controller.
Select your second view controller
From the Attributes Inspector set Presentation to Over Current Context
Note: Make sure your second view controller is presented modally.

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

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.

presentViewController with custom transition

I would like to present a modal UIViewController with a different transitions to the ones available by the toolkit. Precisely I'd like an inverted animation compared to the slide from the bottom (UIModalTransitionStyleCoverVertical), present = slide in from the top, dismiss = slide out from the top.
I don't think there is a simply option for UIModalTransitionStyleCoverVertical to be inverted, so I guess I need to make one on my own.
I am also not using segue/storyboard either, not sure if this makes a difference.
I found some solutions which suggest to simply animate the new viewcontroller view and use presentViewController with the animated option as NO. Unfortunately the problem I have is that the background turns black straight away, even If I define the new viewcontroller view with clear background and not opaque.
Any idea how I could sort this out? Thanks a lot!
I solved the not transparent background issue taking a screenshot and using it as background for the modal view controller.
Apply your custom animation with CATransition.
Set modalPresentationStyle property for the presented view controller to UIModalPresentationCustom (available for iOS 7 or later). See also UIModalPresentationOverCurrentContext iOS8, or UIModalPresentationCurrentContext.
For my case I wanted to the same animation style, but I only needed to use UIModalPresentationOverCurrentContext for iOS 8.

Resources