0

I want to make a UIView stick on the bottom while I am scrolling in my UITableView.

My idea was to set a UIView with the position of right above the navigation item. Set it's zPosition to 1.

The problem is, that the yPosition of my UITableView varies. Any idea how to solve this?

Edit:

Providing Screenshots for visible vs. expected behaviour:

Visible:

This is when I scroll:

This is when I scroll

Expected:

As seen on Tinder Camera Symbol above Table:

enter image description here

Edit2:

This code is what I use to put the rectangle to the bottom. It works until I swipe the UITableView - The rectangle also scrolls up.

let bounds = self.view.bounds
    let yPosition = self.navigationController?.toolbar.frame.minY
    print(yPosition)
    let myView = UIView(frame: CGRect(x: 0, y: yPosition! - bounds.height/6, width: bounds.width, height: bounds.height/6))
    myView.backgroundColor = myColor.rookie
    myView.alpha = 0.8
    myView.layer.zPosition = 1
    myView.isUserInteractionEnabled = true

    self.view.addSubview(myView)
JVS
  • 2,592
  • 3
  • 19
  • 31
  • 1
    why dont you use tablefooterview? – Venk Jul 04 '17 at 12:30
  • Is it necessary to be a UITableViewController instead of UIViewController? – Ahmad F Jul 04 '17 at 12:31
  • a screenshot of expected vs observed would be a plus. – NeverHopeless Jul 04 '17 at 13:25
  • @Venkat the footer view is always on the bottom of the tableview, but it exceeds the view. it needs to be always visible – JVS Jul 04 '17 at 13:38
  • @AhmadF not necessarily, but I got a lot of work put into this and my code is not scalable enough to change easily – JVS Jul 04 '17 at 13:39
  • @NeverHopeless I added screenshots to it. please have a look. – JVS Jul 04 '17 at 13:45
  • @JVS - your pictures don't make much sense. Are the Photo, the thumbs up/down, and the two labels each rows in your table? And you want the orange rectangle to be at the bottom of the screen? If so, why don't you just pin the orange rectangle to the bottom? If that's *not* the case, then try to explain *exactly* what you want... in doing so, you may just figure it out for yourself. – DonMag Jul 04 '17 at 14:17
  • @DonMag Please ignore the photo/Thumbs/two labels. these are elements of a headerView. Pining the orange rectangle to the bottom is the exact thing I am trying to do. As I am not using AutoLayout You can now find my code as **Edit2** – JVS Jul 04 '17 at 15:04
  • 1
    @JVS - OK... take a look at this post - it discusses a couple ways of doing what you want. https://stackoverflow.com/questions/14689805/how-to-put-buttons-over-uitableview-which-wont-scroll-with-table-in-ios – DonMag Jul 04 '17 at 15:24
  • Possible duplicate of [How to put buttons over UITableView which won't scroll with table in iOS](https://stackoverflow.com/questions/14689805/how-to-put-buttons-over-uitableview-which-wont-scroll-with-table-in-ios) – DonMag Jul 04 '17 at 15:24

1 Answers1

0

there is a solution for this. you can do this by disabling the Auto Layout(button.translatesAutoresizingMaskIntoConstraints = false) property of the corresponding Button or any UIView for floating button:

Swift 4

button.translatesAutoresizingMaskIntoConstraints = false
if #available(iOS 11.0, *) {
     button.rightAnchor.constraint(equalTo: tableView.safeAreaLayoutGuide.rightAnchor, constant: -10).isActive = true
     button.bottomAnchor.constraint(equalTo: tableView.safeAreaLayoutGuide.bottomAnchor, constant: -10).isActive = true
} else {
     button.rightAnchor.constraint(equalTo: tableView.layoutMarginsGuide.rightAnchor, constant: 0).isActive = true
     button.bottomAnchor.constraint(equalTo: tableView.layoutMarginsGuide.bottomAnchor, constant: -10).isActive = true
}
manukn
  • 2,608
  • 1
  • 13
  • 17