iOS中的动画——UIView
官方文档Animations详细讲述了UIView的animations, iOS 开发之动画篇 - 从 UIView 动画说起也阐述了用UIView进行动画的基本用法。
总结摘抄一些要点。
Animate Property Changes in a View
Basic Usage
1 2 3 4 |
|
NOTE: When this code executes, the specified animations are started immediately on another thread so as to avoid blocking the current thread or your application’s main thread.
Completion Handler
Usage of Completion Handler
- Use a completion handler to signal your application that a specific animation has finished.
- Completion handlers are also the way to link separate animations together.
Sample code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
Nesting Animation Blocks
Nested animations are started at the same time as any parent animations.
Sample code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
Creating Animated Transitions Between Views
View transitions help you hide sudden changes associated with adding, removing, hiding, or showing views in your view hierarchy. You use view transitions to implement the following types of changes:
- Change the visible subviews of an existing view. You typically choose this option when you want to make relatively small changes to an existing view.
- Replace one view in your view hierarchy with a different view. You typically choose this option when you want to replace a view hierarchy that spans all or most of the screen.
Note: View transitions should not be confused with transitions initiated by view controllers, such as the presentation of modal view controllers or the pushing of new view controllers onto a navigation stack. View transitions affect the view hierarchy only, whereas view-controller transitions change the active view controller as well. Thus, for view transitions, the view controller that was active when you initiated the transition remains active when the transition finishes.
Sampel code for replacing a view with a different view:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Note: In addition to swapping out views, your view controller code needs to manage the loading and unloading of both the primary and secondary views.