The iPhone Developer's Cookbook(5)

总是这样记笔记会严重影响读书效率,有没有什么更好的办法的。读到现在,有点懒惰不想记了。哎,还是不能放弃呀,这次一定要坚持到底。

UIViewControllers
Navigation controllers let users move soothly between views (or, more accurately, view controllers) using built-in animation. They provide history control for free without any programming effort. Navigation controllers automatically handle Back button functionality.

At their simplest level, navigation controllers manage view controller stacks.

Every navigation controller owns a root view controller. This controller forms the base of the stack.

Add new items onto the navigation stack by pushing a new controller with pushViewController: animated:.

Typically, modal controllers are used to pick data such as contacts from the Address Book or photos from the Library, but you can use modal controllers in any setting where it makes sense to perform a task that lies outside the normal scope of the active view controller.

Any view controller or navigation controller can present a modal controller:
[self presentModalViewController:[[[InfoViewController alloc] init] autorelease] animated:YES];

Subviews display onscreen in order, always from back to front. This works something like a stack of animation cells-- those transparent sheets used to create cartoons. Only the parts of the sheets that have been painted show through. The clear parts allow any visual elements behind that sheet to be seen. Views too can have clear and painted parts, and can be layered to build a complex presentation.

The UILayoutContainerView is never used directly by developer. It's part of the SDK's UIWindow implementation.

NSStringFormCGRect(aCGRect) converts a CGRect structure to a formatted string. This function makes it easy to log a view's frame when you're debugging.

CGRectFromString(aString) recovers a rectangle from its string representation. It proves useful when you've stored a view's frame as string in user defaults and want to convert that string back to a CGRect.

CGRectInset(aRect, xinset, yinset) enables you to create a smaller or larger rectangle that's centered on the same point as the source rectangle. Use a positive inset for smaller rectangles, negative for larger ones.

CGRectIntersectsRect(rect1, rect2) lets you know whether rectangle structures interset. Use this function to know when two rectangular onscreen objects overlap.

CGRectCreateDictionaryRepresentation(aRect) transforms a rectangle structure into a standard CFDictionaryRef, also know (via the magic of toll-free bridging) as (NSDictionary *) instances. Transform the dictionary back to a rectangle by using CGRectMakeWithDictionaryRepresentation(aDict, aRect).

CGRectZero is a rectangle constant located at(0,0) whose width and height are zero. You can use this constant when you're required to create a frame but are still unsure what that frame size of location will be at the time of creation.


Views live in two worlds. Their frames are defined in the coordinate system of their parents. Their bounds and subviews are defined in their own coordinate system. To convert a point from another view into your own coordinate system, use convertPoint: from View:, for example:
myPoint = [myView convertPoint:somePoint fromView:otherView];

The iPhone SDK does not expect you to move a view by changing its frame. Instead, it provides you with a way to update a view's position. The preferred way to do this is by setting the view's center.

Change a view's size onscreen by adjusting either its frame or its bounds.
When a view's size changes, the view itself updates live onscreen.

UIView animations work as blocks, that is, a complete transaction that progresses at once. Start the block by issuing beginAnimations:context:. End the block with commitAnimations. Send these class methods to UIView and not to individual views.
    beginAnimations:context -- Marks the start of the animation block.
    setAnimationCurve -- Defines the way the animation accelerates and decelerates.
    setAnimationDuration -- Specifies the length of the animation, in seconds.

你可能感兴趣的:(developer)