Wesley Cho
Wesley Cho

Reputation: 495

Grey bar appearing under Navigation bar after segues Swift

A grey bar exactly the size of my navigation bar + status bar appears under my navigation bar when I segue to the specific VC. In another VC the grey bar isn't there unless I open Youtube then use the iOS 9 "back to 'App'" button.

Here is what it looks like:

enter image description here

As you can see from the picture, the grey bar is not covering the YTPlayerView but is instead shoving it down.

What is going on here?

EDIT

I added the view hierarchy for clarity.

enter image description here

EDIT

I added the constraints for the YTPlayerView in question.

enter image description here

EDIT

Constraint to top layout guide is 0

enter image description here

Upvotes: 3

Views: 2736

Answers (5)

mojtaba al moussawi
mojtaba al moussawi

Reputation: 1398

The cause of this is that the UIWebBrowserView does not fill the entire UIWebViewScrollView of YTPlayerView

If you try to open the view debugger you will see the following :

enter image description here

From the view debugger we can see that the UIWebBrowserView is not filling the entire UIScrollView since the behavior for determining the adjusted content offsets is set to automatic by default, the documentation says :

var contentInsetAdjustmentBehavior: UIScrollView.ContentInsetAdjustmentBehavior { get set }

This property specifies how the safe area insets are used to modify the content > area of the scroll view. The default value of this property is > UIScrollView.ContentInsetAdjustmentBehavior.automatic.

To overcome this behaviour just set the ContentInsetAdjustmentBehavior to .never which will tell the UIScrollView of the player webView to Do not adjust the scroll view insets.

    if #available(iOS 11.0, *) {
       *yourPlayerView*.webView?.scrollView.contentInsetAdjustmentBehavior = .never
    } else {
        // Fallback on earlier versions
    }

Upvotes: 0

user7564352
user7564352

Reputation:

Another way in Swift 3:

func application(_ application: UIApplication, didFinishLaunchingWithOptions 
launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

     // Navigation bar will be black throughout the app
     UINavigationBar.appearance().barStyle = .blackOpaque

    return true
}

Upvotes: 0

Wesley Cho
Wesley Cho

Reputation: 495

I don't fully understand the issue here but it seems to have been a view hierarchy issue?

enter image description here

This was the flawed hierarchy; I changed the color of the stackView to see if it was the culprit but it was not.

I did some more testing and found out that the issue was contained within the YTPlayerView.

enter image description here

The YTPlayerView started out including the grey space but after going to Youtube.com in Safari the using the iOS 9 "Back to App" function the grey bar shoved the view down into itself.

What finally fixed this issue is merely setting the YTPlayerView lower in the hierarchy like so:

enter image description here

The grey bar does not appear after using the "Back to App" function anymore.

Upvotes: 2

Tim
Tim

Reputation: 2098

Your video view is tagged with constraints to the size of your screen AND to the 16:9 ratio you want for the video feed. I can confirm that this creates the grey bar above the video feed. You can try without the aspect ratio (in which case the screen size will set itself).

Upvotes: -1

Harikrishnan
Harikrishnan

Reputation: 8063

I once had a similar issue. It is not related to using segues. the issue is most probably with the constraints you are using. Set the top constraint of the YTPlayerView with respect to the top layout guide instead of top of superview(which you may have currently done). I cannot specifically say a solution for this problem unless I know the constraints you have provided. Providing constraints with respect to the top of the super view causes this kind of issue when you are "Presenting" a view controller and the "Dismissing" it, which is similar to the action you are doing with IOS 9 back to the app option. Just try with the constraint as I mentioned and if it doesn't solve the problem, try to give some details about the constraints you are using.

EDIT

To be more specific, right now you must be setting the top constraint of the YTPlayerView as a fixed distance (which is equal to the height of the navigation bar plus status bar, 64px I assume) to the top of the superview, which is the view of the ViewController. This need to be changed and the top constraint need to be set as 0px to the top layout guide. That should solve your problem.

EDIT 2

Since you are still having problem with it, try connecting the IBOutlet of the top constraint to the ViewController and then in the view controller's viewDidAppear method set it to zero.

Objective C:

topConstraint.constant = 0;
[self.view layoutSubviews];

Swift:

topConstraint.constant = 0
self.view.layoutSubviews()

Just to confirm, the superview of the YTPlayerView is grey in colour right?

Upvotes: 0

Related Questions