【问题标题】:Make a View stick to bottom with UITableViewController使用 UITableViewController 使视图保持底部
【发布时间】:2017-07-04 12:29:02
【问题描述】:

我想在我的UITableView 滚动时在底部制作一个UIView

我的想法是设置一个UIView,其位置位于导航项的正上方。将 zPosition 设置为 1

问题是,我的UITableViewyPosition 不同。 知道如何解决这个问题吗?

编辑:

提供可见行为与预期行为的屏幕截图:

可见:

这是我滚动的时候:

预期:

如上表中的 Tinder 相机符号所示:

编辑2:

这段代码是我用来将矩形放在底部的。 在我滑动 UITableView 之前它一直有效 - 矩形也会向上滚动。

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)

【问题讨论】:

  • 为什么不用tablefooterview?
  • 是否必须是UITableViewController而不是UIViewController?
  • 预期与观察的屏幕截图将是一个加分项。
  • @Venkat 页脚视图始终位于 tableview 的底部,但它超出了视图。它需要始终可见
  • @JVS - 好的......看看这篇文章 - 它讨论了几种做你想做的事情的方法。 stackoverflow.com/questions/14689805/…

标签: ios swift uitableview uiview


【解决方案1】:

有一个解决方案。您可以通过禁用相应按钮的 Auto Layout(button.translatesAutoresizingMaskIntoConstraints = false) 属性或浮动按钮的任何 UIView 来做到这一点:

斯威夫特 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
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-04
    • 2019-01-11
    • 2016-01-21
    • 2015-07-28
    • 1970-01-01
    相关资源
    最近更新 更多