UIView 转 ViewController

330 阅读1分钟

iOS 中将一个全屏展示的 View 修改为 使用 ViewController 的方法。

举例:FullView.swift 为已有的 View,FullView.xib 为其关联的 xib

  1. 新建附带 xib 的 FullViewController.swift
  2. 在 FullViewController.xib 中新增一个 UILabel,添加好约束,添加好 IBOutlet
  3. FullView.xib 和 FullViewController.xib 均打开为 Source Code
  4. 查找 objects 对象中的 view 的 id,用 FullView.xib 中的替换 FullViewController.xib 中的
  5. 如果 FullView.xib 使用了 SafeArea,那么查找 safe area 的 id,同样替换
  6. 从上往下剪切 FullView.xib 中的内容到 FullViewController.xib
  7. 剪切 customFonts
  8. 剪切 view - subviews
  9. 剪切 constraints
  10. 剪切 connections, 注意保留 FullViewController.xib 中原有的一条 view 的 connection,同时删去第二步加的那个 UILabel 的 IBOutlet
  11. 剪切 resource
  12. 剪切 view - color
  13. 剪切 FullView.swift 中的内容到 FullViewController.swift 中,并做适当生命周期方法调整
  14. 如果还有 IBAction 关联找不到的,在 FullViewController.xib 中删除对应那条,重新勾连