在导航栏后面添加图像视图时,拉动刷新指示器会丢失
Pull to refresh indicator gets miss placed when adding imageview behind nav bar
我不明白为什么会这样,但是当我在我的表格视图和导航栏后面添加一个图像视图时,我的导航栏表现得很奇怪:
导航栏卡在静止位置,滚动时不会像以前那样移动
从拉动到刷新的 activity 指示器放置在导航栏按钮和表格视图顶部之间。而不是像以前那样停留在导航栏标题的顶部。
左图是后台没有imageview的bug
右图展示了在没有图像视图的情况下如何完美运行。
我获得清晰导航栏的代码(虽然我认为这不会引入任何问题,因为当背景中的图像视图不存在时它工作正常):
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = true self.navigationController?.view.backgroundColor = UIColor.clear
找到解决办法。
将图片设置为tableview的backgroundview,并将tableview设置为全屏。
let image = UIImage(named: "myphoto")
let iv = UIImageView(image: image)
iv.contentMode = .scaleAspectFill
iv.layer.frame = CGRect(x: 0, y: 0, width: (self.tableView.superview?.frame.size.width)!, height: (self.tableView.superview?.frame.size.height)!)
let tableViewBackgroundView = UIView()
tableViewBackgroundView.addSubview(iv)
self.tableView.backgroundView = tableViewBackgroundView
我不明白为什么会这样,但是当我在我的表格视图和导航栏后面添加一个图像视图时,我的导航栏表现得很奇怪:
导航栏卡在静止位置,滚动时不会像以前那样移动
从拉动到刷新的 activity 指示器放置在导航栏按钮和表格视图顶部之间。而不是像以前那样停留在导航栏标题的顶部。
左图是后台没有imageview的bug
右图展示了在没有图像视图的情况下如何完美运行。
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = true self.navigationController?.view.backgroundColor = UIColor.clear
找到解决办法。
将图片设置为tableview的backgroundview,并将tableview设置为全屏。
let image = UIImage(named: "myphoto")
let iv = UIImageView(image: image)
iv.contentMode = .scaleAspectFill
iv.layer.frame = CGRect(x: 0, y: 0, width: (self.tableView.superview?.frame.size.width)!, height: (self.tableView.superview?.frame.size.height)!)
let tableViewBackgroundView = UIView()
tableViewBackgroundView.addSubview(iv)
self.tableView.backgroundView = tableViewBackgroundView