UINavigationController weird transparency behaviour when presenting - swift

I'm experiencing a weird glitch with the transparent navigation controller. When presenting a view controller with a UIImage at the top of the navigation controller: at first presents half of its background blur with a dark section, and half with a clear one; and after a very short moment it changes for a full dark background. As shown in the gif:
The UIImage displayed is mostly white, the borders are very close to pure white. So the grey color does not make much sense (less sense makes the rapid change).
I did disable extend edges under top bar in the Storyboard for the presented view controller. So the image is not hidden behind the Navigation Controller. With this option enabled the glitch does not appear, but I don't want to hide part of the image.
Disabling the transparency, solves my problem, but I'd like to be able to keep the transparency effect.
Edit: I did notice the "grey effect" also makes the navigation controller opaque. But only for that view, when going back, is transparent again.
Xcode 11, Swift 5, iOS 13.2, iPhone XS.
Thank you very much for your help.

I finally found the problem.
I didn't want the UIScrollView to bounce on top so I used this code:
extension ProblematicViewController: UIScrollViewDelegate {
/// Prevent bounce at top
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView.contentOffset.y < 0 {
scrollView.contentOffset.y = 0
}
}
}
Which meant the ViewController's Adjust Scroll View Insets were overwrite (I think). So my scroll view did lay under the UINavigationController, to prevent this from happening, I did disable Extend Edges: Under Top Bars, so the root UIView containing the UIScrollView was not covered by the UINavigationController. So the transparency effect could never happen because the view was never under the top bar. More about Adjust Scroll View Insets on this post (helped me to find the problem).
Removing those lines and enabling Adjust Scroll View Insets and Extend Edges: Under Top Bars, solves the glitch problem, but the UIViewController does not have the "prevent bounce on top" behaviour that I wanted.
This kinda explains the weird behaviour of the UINavigationController because the SO has to calculate a transparency over nothing, but is sill strange, the transparency effect is calculated when the ProblematicViewController is fully presented, and not on viewDidLoad() or another view's life cycle before is shown to the user, so the transition is smooth, even when nothing lays behind the effect.

Related

Why is View Controller scrolling above UIScrollView?

Autolayout constraints not working properly with UIScrollView, allowing me to scroll above the scrollview even though the scrollview is constrained to the Super View, not the safe area.
Initial Load
Scroll Up
I've added a scrollview to a View Controller and constrained it to each edge of the super view, not the safe area. I've disabled "Adjust Scroll View Insets" in the View Controller as well as "Under Top Bars" and "Under Bottom Bars" within the "Extend Edges" block in the inspector. Everything in the storyboard appears to be correct. Also once I load the View Controller, everything also appears to be correct until I scroll up. I'm sure this relates to the Status Bar because it appears to be the exact height of it but I can't figure out what I'm supposed to adjust. This issue occurs on all devices including devices without notches.
The ScrollView's content inset adjustment behavior needed to be adjusted using scrollView.contentInsetAdjustmentBehavior = .never

tvOS UITableView in UINavigationController causes strange fading behavior (UIView.mask)

I ran into a strange situation when a UITableView is used within the context of a UINavigationController.
tvOS uses UIView.mask to apply a "fade-out gradient" at the top and bottom of a UITableView, so that cells fade into and out of existence at the top and bottom edges of the table view.
That's fine: the fading mask always stays out of the way of the selected cell.
(Here, view.backgroundColor is set to red and tableView.backgroundColor is set to blue with 50% alpha. The constraints of the tableView are set to the safe area.)
The problem comes when you put your view controller inside of a UINavigationController. When selection is near the top, the mask view no longer seems to avoid the cell, so it looks faded. Additionally, as the user scrolls down, the fading mask takes a giant jump downward, and then as the user starts to scroll back up, that fading mask doesn't seem to get out of the way:
For reference, here is the same setup but with tableView.mask = nil:
(All fading is disabled, but you can see the cells "pop" into and out of existence at the top and bottom of the tableview. You might think you could just set tableView.masksToBounds = true, but then the selected cell gets chopped off because it grows when selected)
Surely I'm missing something obvious here? Did no one at apple put a tableview inside of a nav controller?
You were so close! The clips to bounds was missing.
tableView.clipsToBounds = true
tableView.mask = nil
Cheers :)

UITableView won't scroll behind blur views, tab bar, or navigation bar

I'm making a simple app and I love using blue effects throughout the UI. Normally if I use a tableView I pin the 4 edges all the way out to the edge of the viewController, and everything scrolls correctly "behind" the blurred navigation bar and tab bar.
However, for one scene I want one view "Original Post VisualFX View" to be "pinned" at the top while the answer fields scroll behind that view and the nav/bottom bars.
Here's the view hierarchy:
Even after I turned off "clip to bounds" on the tableview as well as every view in the hierarchy above it, I can only get the tableView to scroll a BIT behind the Original Post VisualFX View and the bottom tab bar before they disappear. I assume it's because tableViews don't draw things that aren't visible at all within its bounds.
I'm trying to do everything in the Storyboard in IB with as little code as possible. I feel like this shouldn't be that hard, right?
So after tinkering for a while, I found a workaround: use a TableViewController for the whole scene, and just use a custom TableViewCell as the header, which pins it at the top when you scroll. By using ClearColor for the background and putting a UIVisualEffectView with blur in the background, I'm able to get everything to work beautifully.

Scroll View lightening background color

I am using the same background on different views in my app and remarked something strange with the only view where I use a UIScrollView: the background is lighter than expected.
Uninstalling the scroll view gives it its color back. I am 100% positive this comes from the scroll view only and not it's subviews because uninstalling anything (and everything) else inside the scroll view has no effect.
No scroll view:
Scroll view :
Is there any solution to fix that?

How to autosize view without auto layout in iOS

I have a problem that I can't understand resizing views. My deployment target is iOS 5.0, so I have disabled auto layout in the interface builder to make it compatible with iOS 5.0. The view does not resize automatically. Following is an example:
Interface Builder Snapshot:
4-inch screen:
3.5-inch screen (has problem):
As you can see, the button at the bottom of the view goes out of the screen. The background image also does not resize automatically. I can not understand how I can solve this problem. Can anyone help me?
Welcome to the pre-autolayout world! You must set the autoresizing "springs and struts" so that the stuff at the bottom is attached to the bottom of the superview and not the top. So, struts to the bottom, springs to the top. That way, as the superview gets larger and smaller, the stuff at the bottom moves with the bottom.
You could alternatively reposition the stuff in code, but there's no need in this situation.
Here's the section on autoresizing from my book:
http://www.apeth.com/iOSBook/ch14.html#_autoresizing
The part about the superview and the background image not being resized is a different matter. Is this the view of a UIViewController? If so, then if you are putting the UIViewController into the view controller parent-child hierarchy correctly, it will be resized by its parent. But you have not shown any code, so there's no telling what this view may be or how it is supposed to get into the interface.