源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

iOS11适配工作及导航栏影藏返回文字的解决方法

  • 时间:2022-05-15 17:44 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:iOS11适配工作及导航栏影藏返回文字的解决方法
[b]前言[/b] 本文主要介绍了关于iOS11适配及导航栏影藏返回文字的解决方法,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧。 [b]一、iOS11适配工作[/b] 这是一篇 WWDC Session 204 "Updating Your App for iOS 11" 的总结,里面的内容涉及到了产品、设计以及开发需要了解的内容。 在 "iPad" 以及 "iPhone 的 Landscape" 下, UITabBarItem 图片和文字并排排列了,并且长按 UITabBarItem 会有一个大的 HUD 显示在中间 通过设置 UIBarItem.largeContentSizeImage 可以设置 Tabbar 长按之后显示在中间的图片 (这个功能我在 Beta 2 中没有试出来,只能截取官方的图片) [img]http://files.jb51.net/file_images/article/201710/20171030102653174.jpg?201793010272[/img] iOS 11 为我们带来了 "Large Title",效果如下,当 "ScrollView" 向上滑动时,"Large Title" 会跟着改变, 效果如下: [img]http://files.jb51.net/file_images/article/201710/20171030102722780.gif?2017930102732[/img] "SearchBar" 被移植到了 "NavigationBar" 上面, 提供两种模式,一种是滚动后隐藏 searchBar(如上图), 另外一种就是保留 searchBar 在 Navigation 上。通过以下代码控制
navigationItem.hidesSearchBarWhenScrolling = false
UIToolbar, UINavigationBar 支持 Auto Layout [code]UIView.layoutMargins[/code] 被扩展到了 [code]UIView.directionalLayoutMargins[/code], 支持 Right to Left 语言(和我们关系不大,除非某天我们进军中东的某些国家了)。并且,这两个属性会互相同步 UIViewController 添加 systemMinimumLayoutMargins 属性(说实话,我们布局真的很少用到这个东西,不过可以作为了解) 新增 [code]UIView.safeAreaLayoutGuide[/code],同时废弃 [code]UIViewController.topLayoutGuide [/code]和 [code]UIViewController.bottomLayoutGuide[/code]。如果你之前处理过 UINavigationBar 的translucent,你就会发现 topLayoutGuide 的表现只能用差强人意来形容,希望这次新增的 safAreaLayoutGuide 能够彻底改变这个现状
///safeAreaLayoutGuide 取代 topLayoutGuide 的代码
//subview.topAnchor.constraint(equalTo: self.topLayoutGuide.bottomAnchor).isActive = true
subview.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true
[img]http://files.jb51.net/file_images/article/201710/20171030102827814.jpg?2017930102838[/img] 蓝色区域即:[code]UIView.safAreaLayoutGuide[/code] UIScrollView 新增 adjustedContentInset UIScrollView 新增 frameLayoutGuide 和 contentLayoutGuide, 目的是为了降低 ScrollView Auto Layout 的难度 [img]http://files.jb51.net/file_images/article/201710/20171030102856266.jpg?201793010295[/img] UITabelViewCell 的 rowHeight 默认变成 UITableViewAutomaticDimension, 意味着自动算高会更普及了 UITableView 开放了 "Full Swipe", 就像删除邮件的操作一样 [img]http://files.jb51.net/file_images/article/201710/20171030102930452.gif?2017930102940[/img]
 func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
  return nil
 }

 func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
  let action = UIContextualAction(style: UIContextualAction.Style.destructive, title: "Delete") { (action, view, completionHandler) in
   self.tableView.beginUpdates()
   self.data.remove(at: indexPath.row)
   self.tableView.deleteRows(at: [indexPath], with: UITableViewRowAnimation.left)
   self.tableView.endUpdates()
   completionHandler(true)
  }
  let configuration = UISwipeActionsConfiguration(actions: [action])
  return configuration
 }
[b]二、导航栏影藏返回文字的解决方法[/b] 如果要只保留返回按钮的文字,不需要"返回"文字 iOS11之前,在 全局函数执行的地方使用一下代码:
// barBtn.setBackButtonTitlePositionAdjustment( UIOffset(horizontal:0 , vertical: -70), for: .default) //设置取消返回按钮的字体 
iOS11之后,我的解决办法为,在push的父页面将title设为空 例如:
self.title = "" 
self.navigationController?.pushViewController(workDetail, animated: true) 
这样的话就需要在viewWillAppear方法中每次都设置控制器的title,不然就会导致返回这个页面的时候title不见的。 综合的解决办法,手动添加一个只含返回图标的button,然后在push到目的页面的时候添加。 [b]总结[/b] 以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对编程素材网的支持。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部