码迷,mamicode.com
首页 > 移动开发 > 详细

Stanford iOS Learn Notes - 2

时间:2015-08-02 11:30:00      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:

上一篇文章总结说,Stanford视频前六节需要总结的内容主要分为三部分:

  1. 总结一下教授对iOS的简介
  2. 总结一下教授在这六节课里面讲的语法
  3. MVC,Cocoa Touch, Happiness Demo 

前两部分在上一篇文章里面大概梳理了一下,当时有些知识点的细节没有详解总结,毕竟如果真要总结的话,每个知识点都可展开成一个文章。今天这篇文章主要集中梳理一下第三部分:MVC,Cocoa Touch,Happiness Demo。

1. MVC

Divide objects in your program into 3 “camps”.
Model: What you application is (but not how it is displayed) (Totally UI independent)
Controller:How your model is presented to the user (UI Logic) (Specific to each App)
View: Your controller’s minions (Always generic shared by Apps)
 
The MVC is all about managing communication between camps.
Controllers can always talk directly to their Model.
Controllers can also talk directly to their View. (outlet, if we have the property of View in Controller, it marked as outlet)
The Model and View should never speak to each other.
Can the View speak to its Controller?
Yes, but since the View is always generic, it should talk to Controller in the blind way, i.e. based on the knowledge that it doesn’t know much about Controller. Also, it should talk to Controller in a structured way.
课堂上教授介绍了三个例子:target+action,delegate,data source (View不能包含数据,数据要从Controller中获取,而不是从Model中)。总体上看,这三个都是代理模式的一个应用,Controller把他自己作为View的代理。这个代理方式一般是,定义一个delegate Protocol,然后View里面包含一个有这个协议的句柄。Controller实现这个协议,并把自己赋值给View里面的句柄。标准的代理模式。看起来以后还要在复习一下设计模式呀。

2. Cocoa Touch

标题起的可能不对吧,我也不知道现在讨论的范围是不是就属于Cocoa Touch,等我以后多看几节,应该就知道了吧……

这一节主要是View的概念,和手势的概念。凭直觉来理解,觉得这两部分也应该是View/UI最重要的部分了。大概梳理了一下这些概念,罗列在下面,便于以后复习吧。

  1. View
    1. View就是一个长方形的界面
    2. View是有层次的(Hierarchical)。一个View可以有SuperView,(如果有的话只能有一个,很容易理解)。可以有好多个SubView
    3. 一个View的SubView的顺序是很重要的,数组后面的View显示的前面。
    4. The top of the (useable) view hierarchy is the controller’s var view: UIView
    5. Initializing a UIView:
      1. Try to avoid initialiser if possible
      2. A UIView’s intializer is different if it comes out of a storyboard: init(frame: CGRect), init(coder: NSCoder)
      3. If you need an initializer, you need to implement them both.
  2. Coordinate System Data Structure:
    1. CGFloat/CGPoint/CGSize/CGRect, 切记不要用Float/Double 这些,要不变异就挂了。
  3. View Coordinate System(视图的坐标系统):
    1. Origin is upper left
    2. 弄清楚points和pixels。 Pixels are the minimum-sized unit of drawing your device is capable of. Points are the units in the coordinate system.一个point可能1个或者2个pixels。设计是基于point的。
    3. UIView里面的几个重要性质property:
      1. bounds: CGRect // a view’s internal drawing space’s origin and size
      2. center: CGPoint // the centre of a UIView in its superview’s coordinate system
      3. frame: CGRect // the rect containing a UIView in its superview’s coordinate system
      4. 注意bound和frame的区别
    4. 一般情况下都是通过storyboard创建一个View,也可以通过代码创建,但是比较少用。
  4. 如果画一个drawRect?
    1. 可以使用c类型的API(Core Graphics)
    2. 或者可以使用UIBezierPath Class。(这个时候就应该翻文档了,这里不写了)
    3. UIColor
    4. UILabel
    5. NSAttributedString
    6. Attributed String
    7. UIImageView
    8. UIViewContentMode (Redraw)
  5. Gestures
    1. UIGestureRecognizer
    2. Two ways to using a gesture recognizer:
      1. Adding a gesture recognizer to a UIView(asking the UIView to “reconize” that gesture), Done by the Controller. 
      2. Providing a method to “handle” that gesture (not necessarily handled by the UIView). Done either by the controller or by the Controller.
    3. UIPanGestureRecognizer
    4. UIPinchGestureRecognizer
    5. UIRotationGestureRecognizer
    6. UISwipeGestureRecognizer
    7. UITapGestureRecognizer

3. Happiness Demo

教授在第五节和第六节做了一个Happiness的Demo,主要是演示了上述概念的使用。Demo跟着做了一下,但是还是不是很了解,等待自己熟读几遍代码,再进行总结吧。

Stanford iOS Learn Notes - 2

标签:

原文地址:http://www.cnblogs.com/yuhaos/p/4695223.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!