Lecture 4 - Foundation and Attributed Strings
Casting is unsafe, we have to check which class the id is from before doing this.
2. NSObejct 的 description 方法
description method of NSObject
为了比如调试的目的，实现这个方法是很方便的。 It’s very convient to implement this method in your custom class, for purpose such as debugging.
3. NSObject 的 copy 和 mutablecopy 方法
copy and mutablecopy methods of NSObejct
NSObject 或者其他子类 的这两个方法一般是没有被实现的，除了 NSArray 和 NSDictionary (包括 mutable 类型)
These two method of NSObject and its subclass are not implemented in general except NSArray & NSDictionary (including mutable ones).
4. 利用好 Selector
Take advantage of Selector
Method testing methods take a selector (SEL) Special @selector() directive turns the name of a method into a selector
SEL is the Objective-C “type” for a selector
如果你有一个 SEL 类型的变量，你也可以请求一个对象使用它…
If you have a SEL, you can also ask an object to perform it …
performSelector:withObject: methods in NSObject [obj performSelector:shootSelector];
[obj performSelector:shootAtSelector withObject:coordinate];
Using makeObjectsPerformSelector: methods in NSArray
- (void)addTarget:(id)anObject action:(SEL)action ...;
5. 当心 Property List
Take care of Property List
- The term “Property List” just means a collection of collections
It’s just a phrase (not a language thing). It means any graph of objects containing only:
NSArray, NSDictionary, NSNumber, NSString, NSDate, NSData (or mutable subclasses thereof)
- An NSArray is a Property List if all its members are too So an NSArray of NSString is a Property List. So is an NSArray of NSArray as long as those NSArray’s members are Property Lists.
- An NSDictionary is one only if all keys and values are too
An NSArray of NSDictionarys whose keys are NSStrings and values are NSNumbers is one.
- Why define this term?
Because the SDK has a number of methods which operate on Property Lists.
Usually to read them from somewhere or write them out to somewhere. Example:
- (void)writeToFile:(NSString *)path atomically:(BOOL)atom;
This can (only) be sent to an NSArray or NSDictionary that contains only Property List objects.
Lecture 5 - Protocol, Block, Animation
2. Block 外部变量是只读的，如果想实现读写，变量前需要加 __block 关键字
3. Block 会对调用的对象产生强引用，直到Block执行结束。这也容易导致循环引用。
Lecture 9 - Animation & Autolayout
- ib里使用辅助线布局，然后使用 Reset to Suggested Constraints (⌥⇪⌘=)
- 使用ib里的 Add New (Alignment) Constraints 按钮
- 按住 Control(⌃) 从一个 View 拖动到另一个 View
- UIView的几个重要的属性的动画 Animation of important UIView properties
IMPORTANT: The changes are made immediately, but appear on-screen over time (i.e. not instantly).
UIView‘s class method(s)
- UIView外形的任何改变的动画 Animation of the appearance of arbitrary changes to a UIView
By flipping or dissolving or curling the entire view. UIView’s class method
- Dynamic Animator
Specify the “physics” of animatable objects (usually UIViews).
Gravity, pushing forces, attachments between objects, collision boundaries, etc. Let the physics happen!
3. UIView 动画
- Changes to certain UIView properties can be animated over time
transform (translation, rotation and scale)
- Done with UIView class method and blocks
The class method takes animation parameters and an animation block as arguments. The animation block contains the code that makes the changes to the UIView(s). Most also have a “completion block” to be executed when the animation is done. The changes inside the block are made immediately (even though they will appear “over time”).
- Animation class method in UIView
- Translation Animation
Sometimes you want to make an entire view modification at once
By flipping view over
Dissolving from old to new state
Curling up or down
Just put the changes inside the animations block of this UIView class method …
Animating changes to the view hierarchy is slightly different
Animate swapping the replacement of one view with another in the view hierarchy.
UIViewAnimationOptionShowHideTransitionViews if you want to use the hidden property.
Otherwise it will actually remove fromView from the view hierarchy and add toView.
Lecture - 17 Camera, Core Motion, Application Lifecycle
1. 当 App 的 UI 开始/结束时收到的事件
When your application’s UI starts/stops receiving events …
任何对象都可以接收到如下的通知中心广播。Everyone gets these radio station broadcasts …
它有可能发生在用户切换到其他 app 或者一个电话打了进来。
These might happen because user switched to another app or maybe a phone call come in. Use these notifications to pause doing stuff in your UI and then restart it later.
2. 当程序进入后台 / 前台…
When you enter the background …
You only get a few seconds to respond to this.
- (void)applicationDidEnterBackground:(UIApplication *)sender;
If you need more time, it is possible (see beginBackgroundTaskWithExpirationHandler:).! This is a notification for you to clean up any significant resource usage, etc.!
You find out when you get back to the foreground too …
our Application Delegate gets …
- (void)applicationWillEnterForeground:(UIApplication *)sender; and
Generally you undo whatever you did in DidEnterBackground
applicationDidBecomeActive: soon after receiving the above.