When presenting a modal view controller that has a UIScrollView or a subclass of UIScrollView like UITableView or UICollectionView and using UIModalPresentationStyleOverCurrentContext the presented controllers scrollview doesn't scroll to the top when the status bar is tapped, this behaviour happens in iOS8 but not in iOS7.
One reason why scrolling to the top when tapping the status button doesn't happen is having multiple scroll views. Only one scrollView in a controller should have scrollsToTop enabled while all other scroll views should have it disabled. While this doesn't happen in iOS7, in iOS8 if the presenting controller has a scrollview with scrollsToTop enabled, the presented controller's scrollView won't scroll to the top. Since viewWillAppear,viewWillDisappear are not called when presenting a modal view controller over current context the scroll view in the presenting controller should have it's scrollsToTop property disabled and if desired have a callback that would allow the presented controller to reenable it.
Related
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.
I have a problem that is driving me nuts.
In my app, I have a UIViewController with a header UIView and a UITableView below the header. The view controller is presented in a UINavigationController.
The header view has a subview, which in turn has an embedded MKMapView subview. If I refresh the map view on viewWillAppear(...) the map looks perfect:
However, if I refresh the map anytime after viewDidAppear(...) or leave the page by pushing a new view on the stack, the pin gets offset:
If I present the view without a navigation controller, this problem does not appear.
I have tried setting the edgesForExtendedLayout to none, but that caused the navigation bar area to be hidden altogether.
I have tried setting the visible rect for the map view, but that did not make any difference.
Is there any other way to make the map view not care about being presented in a navigation controller?
I don't know why UITableView has bottom inset automatically despite I make UITabBarController be hidden by calling [setHidden:YES] before.
The view controller who has UITableView is a child of UITabBarController. I already know that automaticallyAdjustsScrollViewInsets helps any UIScrollView get proper 'contentInset' depending on status of it's container view controller.
So, I expected that UITableView's bottom contentInset will be 0 if UITabBar is hidden. But, doesn't do that.
Although automaticallyAdjustsScrollViewInsets is YES, should I manually adjust that value when UITabBar is hidden?
Tab bars have never been meant to be hidden - after all why have a UITabBarController if you want to hide the tab bar. In the documentation, you are warned not to modify the tab bar object directly:
You should never attempt to manipulate the UITabBar object itself
stored in this property.
This is exactly what you are doing when setting it to hidden.
In iOS6 this has worked, but now in iOS7, it doesn't. And it seems very error prone to hide it. When you finally manage to hide it, if the app goes to the background and returns, Apple's layout logic overrides your changes. There are many such triggers.
My suggestion is to change your design. Perhaps display the data modally.
Putting this here for anyone who gets this problem for nested view controllers.
My view controller containment hierarchy is:
UINavigationController
|--UIViewController
|--UITabBarController
|--UIViewController
The last view controller has a UITableView whose scrollIndicatorInsets keep getting offset by the tab bar controller's UITabBar height even if it is hidden.
Solution: Set automaticallyAdjustsScrollViewInsets to false in the view controller that contains the tab bar controller (and is inside the UINavigationController). No need to set additional properties in the tab bar controller itself and the second view controller where the UITableView is.
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
I have a UIScrollVIew in a Navigation controller, I present a Modal View controller from the Navigation controller, which works fine. When I dismiss the modal view controller (from the parent), all the content in my UIScroll view gets moved around and paging is broken. The contents of the scroll view are added programmatically, but the scrollView was created in IB.
Sounds like it has to do with autoresizing behavior as well as the autoresizing masks. In IB, turn off "Autoresize Subviews" in relation to the ScrollView.
Also check its autoresizing mask: does it make sense? Play with its mask and trouble shoot from there. When you create views programmatically, the default autoresize mask may have unexpected behavior.