[iOS]Start Developing iOS Apps (Swift)- 学习笔记

Main Topic


XCode工具描述

9F5C183E8CB48EE3E24E03C854F3D003.png
  • Navigator area(导航区域)
    此区域包含代码目录结构、类结构、搜索代码、build信息、debug断点等
  • Toolbar(工具栏)
    一些模拟器信息现在在这个区域
  • Editor area(编辑区域)
    代码、ui编辑区域
  • Utility area(属性工具区域)
    不同文件会有不同属性

核心文件基本说明

  • AppDelegate
    • 创建App window详细描述见下面
      It defines your AppDelegate class. The app delegate creates the window where your app’s content is drawn and provides a place to respond to state transitions within the app.
    • App入口类,提供一个run loop监控用户输入
      It creates the entry point to your app and a run loop that delivers input events to your app. This work is done by the UIApplicationMain attribute (@UIApplicationMain), which appears toward the top of the file.
  • ViewController
    从UIViewController继承下来的class,主要定义UI行为。
    • lifecycle后续补充
  • Storyboard(场景)
    这个文件类型,定义UI页面(类似android的xml定义ui展示,不过功能更加强大)
    • Canvas(幕布)
      场景(页面)可以定义在这里面
    • Scene
      理解成一个页面或场景。可以在里面添加各种UI组件,Navi行为等
      • 添加方法(choose View > Utilities > Show Object Library,选择一个control,拖拽到canvas空白区域就可以创建一个Scene)
      • 一个Scene对应一个Control源码(这是iOS VM设计模式),可以自己选择相应的ViewControl代码


        DCA07A47F7C009028A56027CA117E4B7.png

        FA74153B49DC0E3627EBCCC12136D0A6.png
      • Outlets
        将Scene与source code关联起来
      • Action
        将Scene里面的组件的行为和代码关联起来
      • Navi
        定义页面跳转行为
      • Delegate
        处理用户输入。通过代理类方式例如:UITextFieldDelegate
  • Assets.xcassets
    • 定义图片资源
      link
  • Info.plist
    • 定义权限,项目配置等
  • ViewController
    基类是UIViewController,基本上所有ViewController都是从它继承而来,在里面初始一个Scene的基本展示流程。
8DBD58D7B830402462D9708ACBBFD01D.png
* viewDidLoad()—Called when the view controller’s content view (the top of its view hierarchy) is created and loaded from a storyboard. 
* viewWillAppear()—Called just before the view controller’s content view is added to the app’s view hierarchy. 
* viewDidAppear()—Called just after the view controller’s content view has been added to the app’s view hierarchy.
* viewWillDisappear()—Called just before the view controller’s content view is removed from the app’s view hierarchy.
* viewDidDisappear()—Called just after the view controller’s content view has been removed from the app’s view hierarchy.

基本内容

  • Custom Control
    link
    • 定义View代码文件,基类UIView
      重写一些核心方法,一些logic处理
    • CustomView显示UI
      • storyboard里面定义view
      • 绑定viewcode,在Identity inspector里面关联相应的View代码。
D2022E2A02ED8D08148035A37F8A1643.png
  • Navigation
    页面跳转
    • Navigation Controller
      • 添加 Choose Editor > Embed In > Navigation Controller.
      • 修改Navigation Bar
        可以修改名字,导航button等
    • Segue
      • 页面跳转模式(Push\Modal\Custom)
      • 处理segue的方法
        override func prepare(for segue: UIStoryboardSegue, sender: Any?)处理Segue事件
        segue.destination可以找到目标对象Viewcontrol进行数据传输
  • Persist Data(数据持久化)
    • NSCoding方案
      • 建立PropertyKey
      • 持久化路径
        static let DocumentsDirectory = FileManager().urls(for: .documentDirectory, in: .userDomainMask).first!
        static let ArchiveURL = DocumentsDirectory.appendingPathComponent("meals")
      • 编解码
        encode(with aCoder: NSCoder)/init?(coder aDecoder: NSCoder)
      • 保存NSKeyedArchiver.archiveRootObject(meals, toFile: Meal.ArchiveURL.path)
      • 读取NSKeyedUnarchiver.unarchiveObject(withFile: Meal.ArchiveURL.path) as? [Meal]
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1、通过CocoaPods安装项目名称项目信息 AFNetworking网络请求组件 FMDB本地数据库组件 SD...
    阳明AI阅读 16,026评论 3 119
  • 用到的组件 1、通过CocoaPods安装 2、第三方类库安装 3、第三方服务 友盟社会化分享组件 友盟用户反馈 ...
    SunnyLeong阅读 14,744评论 1 180
  • 一、站在对方的立场看问题 站在对方的立场看问题,能够让我们更好地得到他人的帮助,获得自己想要的。 某个犯人被单独监...
    好听的暖阳阅读 555评论 0 0
  • 在24岁毕业,没有旅行,只是在家吃吃喝喝。有一天一个人拖着箱子来到大城市,在朋友介绍的公司上班。公司园区里三点一线...
    咩帅阅读 319评论 0 3
  • 我有时候就在想 如果余生你都不主动找我 是不是这辈子都不会再与你有交集 可是只要你与我说话 我看见了一定秒回 或者...
    zhaoyonghui阅读 250评论 0 0