Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 165 Vote(s) - 3.55 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Shrink large title when scrolling (not UITableViewController) iOS 11

#1
I have got a View Controller embedded in a Navigation Controller with prefers large titles option set to true; inside the View Controller there’s a Scroll View.

I want to make the nav bar shrink when scrolling.

How could I achieve this?

_Xcode 9, Swift 4, iOS 11_
Reply

#2
This way is working for me. I followed these steps:

1. Moving the TableView to top of the list (under safe area) in view controller scene.
2. Making FirstView and Loaded by FirstViewContoller.

![The screenshot of the solution][1]

[1]:
Reply

#3
In case someone needs to have some view on top, like a menu, and then a UITableView/UICollectionView, and the large title is not hiding when scrolling, like in this "awesome" picture I made:
[![][1]][1]

You will need to set up all the required constraints for the UIView & for your UITableView/UICollectionView, but the most vital part is:

`make sure your UITableView/UICollectionView is the first subview, and then the UIView or any other views are behind.`

Here is an example of that:

[![][2]][2]

[1]:

[2]:
Reply

#4
I have not achieved this using a UIScrollView but I achieved it with other ViewControllers using a UITableView as first view.

If the tableView is not the first view, the large title fails to hide automatically. You most likely need to make sure your tableView is the first element in the main view’s subviews array.


[![enter image description here][1]][1]


[1]:


I hope that this solves your problem.
Reply

#5
You need to:

1. Pin scroll top view to super view top

2. Add
```
override func viewDidLoad() {
super.viewDidLoad()

scrollView?.alwaysBounceVertical = true
}
```
Reply

#6
If u have problem collapse root navigationBar from presented VC's scrollView, can try this:
Add UIScrollView to RootVC. Important - UIScrollView must be root view(at index 0).
In presentedVC we can use scrollViewDidScroll and set offset on our root UIScrollView.
see [here][1] with gif and code
RootVC view hierarchy:
[screenshot][2] (sorry for link, not enough reputation)

in presentedVC try this

func scrollViewDidScroll(_ scrollView: UIScrollView) {
if #available(iOS 11.0, *) {
let offset = scrollView.contentOffset
rootVC.scrollView.contentOffset = offset
}
}


[1]:

[To see links please register here]

[2]:
Reply

#7
I had the similar problem, is was because of many `UIScrollView`-based view inside view controller and I was scrolling not first in hierarchy. Once it's only one it works fine with `UIScrollView`, `WKWebView` or `UITextView` without any line of code.
Reply

#8
I tested with storyboard approach, it is working. **Make sure to set the scrollView & it's subviews Constraints**.

Here with the test sample XCode project for references: [

[To see links please register here]

][1]


[1]:

[To see links please register here]

Reply

#9
Try something like this:

extendedLayoutIncludesOpaqueBars = true
scrollView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(scrollView)
NSLayoutConstraint.activate([
scrollView.topAnchor.constraint(equalTo: view.topAnchor),
scrollView.leftAnchor.constraint(equalTo: view.leftAnchor),
scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
scrollView.rightAnchor.constraint(equalTo: view.rightAnchor)
])
Reply

#10
Setting prefersLargeTitles in code did work for me to make the NavBar title shrink and grow as you scroll. I did notice if you set the property through InterfaceBuilder, the shrinking feature didn't work.

[![IB Property Inspector][1]][1]


[1]:


Instead set in code like

self.navigationController?.navigationBar.prefersLargeTitles = true
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through