2012年11月2日 星期五
[iOS] CS193P 2011 Fall Lesson Two
- All the outlet only needs to be weak, 因為會綁在 view下, 而 view always strong
- control + 滑鼠來 link view與 viewController
- 搞清楚 action與 IBOutlet
- action: view的部分, 使用者接觸或做了什麼事, 來通知 viewController, 所以像是 OnClicked
- IBOutlet: viewController需要 view做什麼改變的橋梁
- id: pointer to any (unknown) type
- debug:
- NSLog:
- 很像 printf
- sample: NSLog(@"The digit you pressed is %@", digit);
- 你也可以使用 %d: integer, %g: floating number等等, 而 %@是針對 object, 其會呼叫 [digit description] 來顯示
- 快速搜尋文件
- option+滑鼠至於 method上
- wrapper
- NSNumber
- wrap primitive data type into object
- synthesize never allocate, only for pointer
[Eng] 每日一課
- 我就直說啦
- Let me get something straight
- 娘娘腔
- sissy
- 有用
- come in handy
- Diary 通常為女生在寫, 且以 Dear diary開頭
- 想歪
- get the wrong idea
- 一堆
- a bunch of
- 白癡
- moron
- 蠢
- dumb, p.s. b不發音
- hit / hit / hit, 三個時態都相同
- "抽高"登大人時期
- growth spurt, 用 hit growth spurt代表達到發育期
- 大猩猩
- gorilla
- 刮鬍子
- shave
- 霸凌
- bullying
- 座位表
- seating chart
- 用力丟下
- plunk
- 永久
- permanent
- 笨蛋
- dork
- n年級
- in the n-th grade
- 屁股
- butt
- 搔頭
- scratching one's head
- 令人厭惡
- stink, 動詞
- stinky, 形容詞
- 大便
- poo
- 黏人
- stick with someone
- 爭奪
- scramble
- 牙套
- braces, 動詞用 get
[iOS] iOS: import, property, protocol
- 用 #import來加入 package, import與 include最大的差異在於不用在人工加入 #ifndef 與 #endif, compiler已經幫我們做掉可能會發生重複 include的情形
- access rules
- public: @interface in .h
- private: @interface in .m, 但是方法後面要加 (), e.g. @interface privateMethod()
- @property
- build-in getter and setter
- private: -(double) value;
- public:
- -(double) value {return value;}
- -(void)setValue: (double) val {value = val;}
- 合成.h中: @property (nonatomic) double topSpeed; 而 .m中: @synthesize topSpeed =_ topSpeed;
- nonatomic為 not thread-safe的 keyword
- 上面其實就是實作了
- -(void) setTopSpeed: (double) speed
- {
- _topSpeed = speed;
- }
- -(double) topSpeed
- {
- return _topSpeed;
- }
- 可清楚看到不用 @synthesize topSpeed; 而是 @synthesize topSpeed = _topSpeed; 主要怕第二個 getter方法名與 member實際名稱相同帶來的困擾
- 另外也可以設定 pointer, 通常會搭配 strong的屬性, strong代表不會自動回收, 而 weak則是沒人用了就回收
- static
- return type前面 -為 non-static, +為 static
- @protocol
- non-class-specific methods
- @interface 對應 Java的 @class, 而 @protocol對應 Java的 @interface
- Ref: Protocol in Objective-C
- @category
- 擴充既存 class
- 一般只用於加 method
- 若擴充的 method檔名已存在, 則會以 category定義的為主
- Ref: Category in Objective-C
- 傳 message給 nil:
- 不像 c++會 crash, 這會....nothing happened, 在 debug要特別注意
- all objects in objective-C are in heap
2012年11月1日 星期四
[iOS] Graphics and Drawing in iOS
- UIKit Graphics System
- 不管是 OpenGL, Quartz, UIKit, Core Animation皆被 UIView的物件限制住. 因此, 若使用系統預設的 view, drawing會自動完成. 而若是 customized則須自己將 drawing code補完. 若使用 OpenGL, 一旦設定好 rendering surface, 則之後皆用 OpenGL提供的 drawing model做操作
- View Drawing cycle
- updating data on demand
- 需要 redraw時, UIView都會呼叫 drawRect: method並將需要重劃的 rect區域傳給該 method, 因此, 在客製化的 view中, 需要覆寫此 method
- update被 triggered的時機:
- 移動或移除某個曾遮隱該 view的 view時 (e.g. view2原本在 view1前面, 當 view1被關閉時, view2的 update動作會被呼叫)
- 將原本 visible 的 hidden屬性改為 No時
- 某 view被 pop回來時
- 明確呼叫 setNeedsDisplay或 setNeedsDisplayInRect: methods時
- 當 drawRect被呼叫時, 該 view的屬性會被改為 updated, 在等待下次 update被 trigger的時機
- 座標系統
- UIKit
- 左上角為原點,向右及向下為正
- current transformation matrix (CTM) 為一轉換矩陣, 由 view座標系統轉至裝置 (device) 座標系統的矩陣, 此矩陣在 drawRect被呼叫時會先做 configuration的動作使其 match目前 view的原點, 另外, 可藉由改變 scaling, rotation, translation來改變 CTM
- 畫圖可以利用建立 paths, 或是更簡單的利用改變 CTM來達成, 相較而言, 後者的 cost較低
- 改變 CTM的方法
- 直接對 CTM做運算, 可參考 CGContext Reference
- 建立一個 CGAffineTransform, 然後 concate該 matrix與 CTM, 細節可再參考 Quartz 2D Programming Guide 和 CGAffineTransform Reference
- Graphics Context
- 呼叫 drawRect: method前, view object會自動 configure, 除了 CTM (包含在 Graphics Context中)外, 還有重要的 configuration就是 graphics context, 他定義了顏色、切割區域 (clipping area)、線寬、風格資訊 (style information)、字型 (font) 資訊等等
- 尤其在建立 image及 PDF 檔案時, 尤其需要自行先建立一個 context來做一系列的 drawing commands, e.g. function: CGBitmapContextCreate、CGPDFContextCreate, ...
- 進階參考: Quartz 2D Programming Guide、CGContext Reference、CGBitmapContext Reference、CGPDFContext Reference
- 可怕的座標轉換
- 看似簡單的座標系統, 其實滿複雜的. 因為 UIKit以 upper-left-origin (ULO) 為主, 而 Core Graphics 則是 lower-left-origin(LLO)為主, 兩者需要一個 flipping的轉換
- 在某個 view中, 欲使用 Core Graphics作圖, 需要有 Graphics Context, 此時可以 UIGraphicsGetCurrentContext方法取得
[iOS] About Drawing and Printing in iOS
- Drawing Paths
- use native drawing
- Core Graphics and UIKit
- using drawRect: method to draw shapges, text, images, or gradients
- redraw- call setNeedsDisplay or setNeedsDisplayInRect: method
- use OpenGL ES
- key concepts
- in drawRect: method, UIKit creates a graphics context to render
- coordination
- origin: top-left of the view
- logical coordination space
- distance: in points, not pixels
[iOS] Windows and Views
- Windows
- 本身沒有任何內容 (content),他提供的是一個 app的 container,來存 views。
- 通常只有一個 window,除非有其他的螢幕畫面。
- 一個 app至少一個 window、一個 view
- instance of UIWindow
- Views
- 放置真實內容,例如 images, text, shapes, and so on。
- 其為 windows的一部分。
- instance of UIView
- manages a rectangular area in your application window
- responsible for drawing content, handling multi-touch events(by gesture recognizer or handing touch events directly), managing layout of subviews
[Notes] Graphics & Animation Starting Point
- Frameworks
- UIKit
- Objective-C API
- basic 2D drawing, image handling, ways to animate user interface objects
- Core Graphics
- C-based API
- vector graphics, bitmap images, PDF content
- Core Animation
- Objective-C API
- smooth motion and dynamic feedback to UI
- OpenGL ES
- OpenGL mobile version
- high-performance 2D and 3D drawing
- includes EAGL, an Objective-C API integrates OpenGL with Core Animation and UiKit
- Guides
- basic draw (UIKit)
- View Programming Guide for iOS
- iOS native coordination system, operations on views
- Drawing and Printing Guide for iOS
- using UIKit to draw
- CGContext Reference to find function call
- powerful 2D draw (Core Graphics- with Quartz 2D engine)
- Overview of Quartz 2D
- create pattern, path, gradient
- Quartz 2D Programming Guide
- animation
- chapter Animations in View Programming Guide for iOS
- sample: MoveMe
- games and advanced graphics by GPU
- OpenGL ES Overview
- sample: GLSprite
- Advanced studying (details)
- UIKit Framework Reference
- Core Graphics Framework Reference
- Core Animation Programming Guide
- OpenGL ES Programming Guide for iOS
- OpenGL ES Framework Reference
2012年10月25日 星期四
訂閱:
文章 (Atom)