23.3 C
New York
Wednesday, September 18, 2024

ios – Why does UIToolBar flip clear/translucent when desk view scrolls underneath it


I’ve a UITableViewController and when the consumer faucets an “edit” button, I show a toolbar on the backside of the display screen. I create a shadow on prime of the toolbar. It seems to be nice (till I modified the colour to make it extra apparent shat’s going incorrect). After I scroll the desk up, as quickly as the underside of the desk comes out from behind the toolbar, the toolbar colours all grow to be clear or do one thing that appears clear.

Here’s a image of the display screen when the desk has knowledge that flows underneath the toolbar:

enter image description here

Here’s a image of the display screen as I drag the desk up and the final merchandise is barely partly underneath the toolbar:

enter image description here

Lastly, once I drag the desk as fr up as I can and the final merchandise is totally above the toolbar, I get this:

enter image description here

It’s apparent that the toolbar background is altering opacity because the desk is scrolling. I have to disable this. I’ve tried varied combos of checking and unchecking the “underneath backside bars” and “underneath opaque bars” within the storyboard. I’ve tried including an empty footer and never including an empty footer to the desk. Right here is the code that creates the toolbar. Word that I am utilizing a desk view controller inside a tab bar controller and hiding the tab bar when the consumer edits the desk:

public func setEditingWithTabController( _ modifying: Bool, animated: Bool, tabController: UITabBarController ) {
    if navigationController == nil || navigationController!.toolbar == nil {
        return
    }
    navigationController!.setToolbarHidden( !modifying, animated: true )
    
    var gadgets = [UIBarButtonItem]()
    
    let versatile = UIBarButtonItem( barButtonSystemItem: .flexibleSpace, goal: self, motion: nil )
    deleteButton = UIBarButtonItem(title: Strings.Delete.localized, model: .plain, goal: self, motion: #selector(didPressDelete))
    deleteAllButton = UIBarButtonItem(title: "Delete All", model: .plain, goal: self, motion: #selector(didPressDeleteAll))
    gadgets.append( deleteAllButton! )
    gadgets.append( versatile )
    gadgets.append( deleteButton! )
    tabController.setToolbarItems( gadgets, animated: false ) // toolbar will get its gadgets kind the present view controller
    
    let bar = navigationController!.toolbar!
    bar.backgroundColor = AppSettings.appBackgroundColor.isDark ? AppSettings.appBackgroundColor.lighten( quantity: 0.05 ) : AppSettings.appBackgroundColor.darken( quantity: 0.05 )
    bar.barTintColor = AppSettings.appBackgroundColor.isDark ? AppSettings.appBackgroundColor.lighten( quantity: 0.05 ) : AppSettings.appBackgroundColor.darken( quantity: 0.05 )
    
    bar.layer.shadowColor = UIColor.crimson.cgColor //AppSettings.appBackgroundColor.isDark ? UIColor.lightGray.cgColor :  UIColor.lightGray.cgColor
    bar.layer.shadowOpacity = AppSettings.appBackgroundColor.isDark ? 0 : 0.5
    bar.layer.shadowOffset = CGSize.zero
    bar.layer.shadowRadius = AppSettings.appBackgroundColor.isDark ? 0 : 20
    bar.layer.borderColor = UIColor.clear.cgColor
    bar.layer.borderWidth = 0
    
    bar.clipsToBounds = false
    bar.isTranslucent = false
    bar.isOpaque = true

    tableView.setEditing( modifying, animated: true )
    
    if modifying {
        refreshControl?.removeFromSuperview()
        tableView.backgroundView = nil
    } else {
        refreshControl = UIRefreshControl()
        refreshControl!.addTarget( self, motion: #selector( refreshData(_:) ), for: .valueChanged )
        tableView.backgroundView = refreshControl
    }
}

This identical factor occurred earlier than I added any of the shadow layer code however was a lot much less apparent with the background merely altering from white to mild grey once I scrolled the desk.

The operate above will get referred to as when the consumer faucets the “edit” button within the app header. Clearly I needn’t configure the toolbar each time this occurs and particularly when hiding it – I am going to fear about fixing all of that later. I want to determine why I am unable to get a clear unchanging toolbar. heck, I am unable to even appear to do away with the grey line on the prime of the toolbar regardless that I am setting the border measurement to zero. This factor has a thoughts of its personal!

[CORRECTION]…

I used to be not setting a background shade. Now once I set a background shade, I get the translucency solely underneath the toolbar within the protected space inset like this:

enter image description here

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles