App Store排行榜页面导航栏效果如何实现
Posted
技术标签:
【中文标题】App Store排行榜页面导航栏效果如何实现【英文标题】:How to implement the NavigationBar effect of AppStore ranking list page 【发布时间】:2017-01-12 08:53:46 【问题描述】: 我使用以下代码增加 NavigationBar 高度override func viewDidLayoutSubviews()
setUpSegmentControll()
let view = UIView(frame: CGRect(x: 0, y: 44, width: ScreenWidth, height: 40))
view.backgroundColor = UIColor.init(colorLiteralRed: 89/255, green: 89/255, blue: 89/255, alpha: 1)
segmentControll.center.x = view.center.x
view.addSubview(segmentControll)
self.navigationController?.navigationBar.addSubview(view)
但是段点击没有效果,代码有什么问题
【问题讨论】:
输出屏幕是什么样的? oikehvl7k.bkt.clouddn.com/… 制作自定义视图并在导航栏下修复它?在 viewWillAppear 和 viewWillDisappear 方法中隐藏或显示。 【参考方案1】:您需要增加导航栏的大小。试试下面的代码,它工作正常
import UIKit
/*extension UINavigationBar
open override func sizeThatFits(_ size: CGSize) -> CGSize
var rect = self.frame;
let screenRect = UIScreen.main.bounds
rect.size.width = screenRect.size.width
rect.size.height = 104
return rect.size
*/
class ViewController: UIViewController
override func viewDidLoad()
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.navigationController!.navigationBar.clipsToBounds = true
override func viewDidAppear(_ animated: Bool)
self.navigationController!.navigationBar.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: 104.0)
override func viewWillDisappear(_ animated: Bool)
self.navigationController!.navigationBar.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: 64.0)
override func viewDidLayoutSubviews()
let segmentControll = UISegmentedControl(items: ["1","2"])
segmentControll.frame = CGRect(x: 0, y: 5, width: 300, height: 30)
let view = UIView(frame: CGRect(x: 0, y: 64, width: UIScreen.main.bounds.size.width, height: 40))
view.backgroundColor = UIColor.init(colorLiteralRed: 89/255, green: 89/255, blue: 89/255, alpha: 1)
segmentControll.center.x = view.center.x
view.addSubview(segmentControll)
self.navigationController?.navigationBar.addSubview(view)
【讨论】:
感谢您的回复,但是所有页面的UINavigationBar都会增加,如何增加一页 删除扩展 UINavigationBar,我已经用两种方法更新了答案。【参考方案2】:您必须增加导航栏的高度。参考下面的链接增加导航栏的高度
How to increase the height of UINavigationBar?
【讨论】:
以上是关于App Store排行榜页面导航栏效果如何实现的主要内容,如果未能解决你的问题,请参考以下文章
Windows Store App XAML - 如何获取导航页面的文本框值