为什么ViewController的Y轴起始点从导航栏下方开始?

         最新在适配业务的某个页面时,发现VC的Y方向的起始点从导航栏的下方开始,而且VC里面嵌入的tableView组件的位置也从导航栏的下方开始,但是在适配导航栏的时候发现,导航栏的背景是VC父视图的背景(导航栏有模糊效果),这就造成了在视觉上导航栏的背景与当前页的背景不一致

          原来在iOS7之后,UIViewController默认为full screen,但是由于项目历史悠久,并且很多控件都是自定义的,很多原因造成了VC的Y轴起始点从导航栏下方开始,未解决这个问题,使用VC的两个属性,分别是extendedLayoutIncludesOpaqueBars和edgesForExtendedLayout来解决。

  1.  extendedLayoutIncludesOpaqueBars默认值时NO,用于当Bar使用了不透明图片时,VC的视图是否延伸至Bar所在区域。
  2.  edgesForExtendedLayout默认是UIRectEdgeAll,表示该VC的视图是否覆盖到四周的区域。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
旅游网站导航栏控制器的关键代码会根据具体实现方式不同而有所不同,下面是一个简单的示例: ```swift class NavigationBarViewController: UIViewController { // 导航栏控件 let searchBar = UISearchBar() let segmentedControl = UISegmentedControl(items: ["国内游", "出境游", "周边游"]) let filterButton = UIButton(type: .system) override func viewDidLoad() { super.viewDidLoad() // 添加导航栏控件 searchBar.placeholder = "搜索旅游目的地" navigationItem.titleView = searchBar segmentedControl.selectedSegmentIndex = 0 navigationItem.titleView = segmentedControl filterButton.setTitle("筛选", for: .normal) navigationItem.rightBarButtonItem = UIBarButtonItem(customView: filterButton) // 设置导航栏外观 navigationController?.navigationBar.tintColor = .white navigationController?.navigationBar.barTintColor = .blue navigationController?.navigationBar.isTranslucent = false navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white] } // 搜索按钮击事件 func searchBarSearchButtonClicked(_ searchBar: UISearchBar) { // 处理搜索逻辑 } // 分段控件击事件 @objc func segmentedControlValueChanged(_ segmentedControl: UISegmentedControl) { // 处理分段逻辑 } // 筛选按钮击事件 @objc func filterButtonTapped(_ sender: UIButton) { // 处理筛选逻辑 } } ``` 这个示例中,`NavigationBarViewController` 是一个 UIViewController 子类,用于管理导航栏控件。在 `viewDidLoad()` 方法中,我们添加了三个控件:`searchBar`、`segmentedControl` 和 `filterButton`。然后,我们还对导航栏外观进行了一些设置。最后,我们还添加了三个事件处理方法:`searchBarSearchButtonClicked(_:)`、`segmentedControlValueChanged(_:)` 和 `filterButtonTapped(_:)`。这些方法会根据不同的控件事件来处理对应的业务逻辑。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员的修养

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值