【发布时间】:2015-05-08 18:51:43
【问题描述】:
我在这里创建了一个示例应用程序:https://github.com/steffimueller/LTNavigationBar-TestProject
当您拉下图像上方顶部的表格时,会出现白色背景。这不应该是这样。标题图像应始终绑定在屏幕顶部。这是我的情况:
它应该是这样的:
之前的截图来自this app,使用了 git repo 的parallax 分支。它是视差演示中的第一个选项卡,具有我想要的效果。
这是我用来创建表格的代码:
class Page1ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var tableView: UITableView!
var topView:UIView!
var topImageView: UIImageView?
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.setLeftBarButtonItem(UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Cancel, target: self, action: "sdfsdf"), animated: true)
self.tableView.delegate = self
self.tableView.dataSource = self
self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: cellIndentifier)
self.navigationController?.navigationBar.lt_setBackgroundColor(UIColor.clearColor())
tableView.autoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleWidth
topView = UIView(frame: CGRectMake(0, 0, 320, 212))
topView.contentMode = UIViewContentMode.ScaleToFill
topView.autoresizesSubviews = true
topView.backgroundColor = UIColor.yellowColor()
topView.clipsToBounds = true
tableView.tableHeaderView = topView
let img = UIImage(named: "bg")
topImageView = UIImageView(image: img)
topImageView?.frame = CGRectMake(0, -89, UIScreen.mainScreen().bounds.size.width, 307)
topImageView?.contentMode = UIViewContentMode.ScaleToFill
topView.addSubview(topImageView!)
}
func scrollViewDidScroll(scrollView: UIScrollView) {
let color: UIColor = UIColor(red: 0/255, green: 175/255, blue: 240/255, alpha: 1)
let offsetY:CGFloat = scrollView.contentOffset.y
if offsetY > NAVBAR_CHANGE_POINT {
let alpha:CGFloat = 1 - ((NAVBAR_CHANGE_POINT + 64 - offsetY) / 64)
self.navigationController?.navigationBar.lt_setBackgroundColor(color.colorWithAlphaComponent(alpha))
}
else {
self.navigationController?.navigationBar.lt_setBackgroundColor(color.colorWithAlphaComponent(0))
}
if offsetY < 0 {
let progress:CGFloat = fabs(offsetY) / 300
self.topImageView?.transform = CGAffineTransformMakeScale(1 + progress, 1 + progress)
}
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
tableView.snp_makeConstraints { (make) -> Void in
make.top.equalTo(self.view).offset(-64)
}
}
}
编辑:我不想设置tableView.bounces = false。
我怎样才能像第二个屏幕截图一样将 TableHeader Image 始终粘贴在屏幕顶部?
【问题讨论】:
-
你试过设置你的
UITableView框架吗? -
正如 dave button 的回答所示,这个问题还不够清楚。
-
«我想在没有故事板的情况下重建这个:github.com/ltebean/LTNavigationBar。» 代码中没有任何内容可以让您使用故事板。
-
@vikingosegundo 问题是示例代码与故事板一起使用,而我的代码使用界面生成器但得到不同的结果。
-
@stephan1001,实际上很难找出您的期望。原始代码和您开发的代码似乎相同。只是不同的是你的代码对 HeaderView 有上浆效果。你能详细说明你想要什么功能吗?
标签: ios objective-c uitableview swift