UIButton stays highlighted until UITableView ends scrolling - ios

I have my own custom navigation controller(that subclasses UIViewController) that has a stack for the view controllers. It has a custom navigation bar and a content view, where I add the view of the view controller at the top of my stack of view controllers.
Then navigation bar, which is a subclass of UIView, I didn't subclass UINavigationBar, because I don't need to, has a Back button, and another button which at this moment doesn't have any action connected.
My problem is that if I scroll a UITableView (that belongs to the current view controller on the stack) and I press either on my back button or on the other button, both of them stay highlighted until the UITableView ends scrolling. It's the weirdest behavior ever, and I don't understand why it happens.
Any suggestions please?

Apparently, if I call [button setHighlighted:NO] on my IBAction it de-highlights it even if the UITableView is still scrolling

Related

How to hide navigation bar on scroll except when at the top of the screen

I have a UIViewController that contains a UICollectionView pinned to all edges of the view. This view controller is inside a UINavigationController.
I want to gradually hide the navigation bar as I scroll down in the collection view. At the point that I have scrolled the distance of the height of the nav bar, the nav bar should be completely hidden. If I scroll back up it should gradually show the nav bar.
I have tried all the open source navigation bars on github, but none of them work correctly with iOS 12.
How can I achieve this?
UICollectionView is a subclass of UIScrollView and therefore you have access to its scrollViewDidScroll delegate method. Your UIViewController is also owned by its navigation controller, so you can create an instance property in the view controller, like navigationDelegate: UINavigationController?, that will act as a delegate. In the navigation controller, set that property equal to self and manipulate the nav bar however you want through the scroll delegate. Absolutely no need for third-party scripting for something this standard and basic.

Adding subview to UITabBar that goes behind other UITabBar subviews

I am trying to add subview to UITabBar which should be behind other UITabBar Subviews.
I added the subview like this in my subclass of UITabBarController:
self.tabBar.addSubview(CustomTabBarController.xView!)
and then I send it to back as below:
self.tabBar.sendSubview(toBack: CustomTabBarController.xView!)
Problem is it doesn't go back and always appear infront. Also, even when this is the case, I am able to tap on tabbaritems. Is something wrong with UITabBar properties? or else, What am I doing wrong?
A view that a subview of view A can't be behind view A. Think of a subview as being on the page of it's parent view.
It's also likely that a tab bar does not allow you to add subviews to it. Apple's UI controls are usually built to fully manage their view hierarchies, and the results of trying to insert subviews or otherwise mess with the view hierarchy are often undefined.
If you want a view to be behind another view the two views need to have the same parent view. You need to tell the tab bar's superview to add your new view behind the tab bar:
self.tabBar.superview. insertSubview(CustomTabBarController.xView!,
belowSubview: self.tabBar)
Also note that your use of force-unwrapping is ill-advised

Multiple Navigation Bar

I need to put 2 NavigationBars. The second will be below the first one.
My idea is:
In the first navigation bar have the navigation buttons and in the second have only a label centered.
The rest is a UITableView controller. When the users scroll, the content hide below the navigation bars.
Paulw11 was right, you probably should create custom view, add a couple of buttons to it and attach it to the bottom of navigation bar using AutoLayout. If you need to hide this view when user scrolls, you can implement func scrollViewDidScroll(scrollView: UIScrollView) method in your UITableViewController and change it's alpha to zero.

TableView Scrolls Over NavBar

When I scroll my TableView, it scrolls over my navigation bar (which I made without using the built in navigation bar for various reasons). See below:
Unscrolled:
Scrolled up:
How do I make it so that the TableView scrolls under the Navbar?
SOLVED:
I checked the "clips subviews" box for the table view to fix this problem.
To me, it looks like there may be an issue with your view hierarchy. Now, I assume that you built your own navigation bar by subclassing UINavigationBar.
In order to get the kind of behavior you need, you should have the following:
UIWindow's rootViewController is an instance of UINavigationController.
UINavigationController.navigationBar = your subclass of UINavigationBar.
UINavigationController.viewControllers[0] = UITableViewController
The UITableViewController.view = your UITableView

scrollViewWillBeginDragging in UITableView does not work

UIScrollView|
UITableView
I have 5 UITableView in UIScrollView.
My program has a Navigation Controller inside TabbarController.
When I run the program, everything is OK. It can drag up and down to refresh data in tableview. It can drag left and right to change tableview.
But when I push the button on the Navigation Bar, it will push a view.
Then I push the back button on the navigation bar on this view.
The scrollViewWillBeginDragging in UITableView not worked. I can just receive the scrollViewWillBeginDragging in UIScrollView.
More worse, it can drag all directions.
Why?
already fix this bug , set self.automaticallyAdjustsScrollViewInsets = NO;

Resources